Skip to content

Allow Enum objects part of a type map to be serialized and deserialized#105

Open
agustingomes wants to merge 4 commits intoCrell:masterfrom
agustingomes:issues/10
Open

Allow Enum objects part of a type map to be serialized and deserialized#105
agustingomes wants to merge 4 commits intoCrell:masterfrom
agustingomes:issues/10

Conversation

@agustingomes
Copy link
Copy Markdown
Contributor

Description

This proposed change aims to allow Enum objects part of a TypeMap to be serialized and deserialized by establishing a serialized structure expected when working with enums in this context.

Motivation and context

fixes #10

How has this been tested?

composer all-checks helped validate the proposed changes.

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

Please, please, please, don't send your pull request until all of the boxes are ticked. Once your pull request is created, it will trigger a build on our continuous integration server to make sure your tests and code style pass.

  • I have read the CONTRIBUTING document.
  • My pull request addresses exactly one patch/feature.
  • I have created a branch for this patch/feature.
  • Each individual commit in the pull request is meaningful.
  • I have added tests to cover my changes.
  • If my change requires a change to the documentation, I have updated it accordingly.

"require": {
"php": "~8.2",
"crell/attributeutils": "~1.3",
"crell/attributeutils": "dev-master#a118b55 as 1.3.1",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging this PR (if that is the direction we want to move towards) I will make sure I update this to a released version.

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class TypeMapTest extends TestCase
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a separate test class means you don't get any of the automatic "test on all formatters" logic. This should instead be a method in the SerdeTestCases class (with appropriate Group). Then follow the pattern in ArrayBasedFormatterTestCases to decode the data to ensure it serialized correctly. That way we get a full round-trip test on all formatters.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be possible to use one of the existing data providers on the main bulk-test, although that may be too complicated. A new method is fine if so, as long as it follows the established pattern.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look into applying the changes for the tests the next days.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took longer than I anticipated.

I took a look at the classes you mentioned, I think I got the gist of how you wanted me to organize the test additions. Let me know if what was added works for you.

PHPStan latest version (2.1.44 at the time of this commit) likely is detecting the first `match` statement throws an exception, and therefore flags the second `match` statement with a `match.alwaysTrue` rule.
This change uses the upstream commit allowing Crell#10 to be fixed.

NOTE: it is expected a new release of `crell/attributeutils` to be released. using directly the hash is for the purpose of validating the implementation changes in this PR
This commit implements serialization of an enum within a Type Map.

Therefore, individual enums being passed in a list, would be serialized as:

```
{"type": "enum", "value": "the-enum-value"}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enums lose type information when serialised as part of a static map

2 participants