Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Fix git dubious ownership
run: git config --global --add safe.directory '*'

- name: Validate composer.json
run: composer validate

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"symfony/property-info": "^6.3|^7.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.10",
"doctrine/orm": "^2.13",
"doctrine/doctrine-bundle": "^2.18",
"doctrine/orm": "^3.5",
"nelmio/api-doc-bundle": "^4.13",
"slevomat/coding-standard": "^8.14",
"slevomat/coding-standard": "8.22",
"symfony/dotenv": "^6.3|^7.0",
"symfony/test-pack": "^1.1",
"symfony/uid": "^6.3|^7.0",
Expand Down
10 changes: 5 additions & 5 deletions src/Handler/Handlers/ArrayStringHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use AnzuSystems\SerializerBundle\Context\SerializationContext;
use AnzuSystems\SerializerBundle\Exception\SerializerException;
use AnzuSystems\SerializerBundle\Metadata\Metadata;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\TypeInfo\TypeIdentifier;

final class ArrayStringHandler extends AbstractHandler
{
Expand Down Expand Up @@ -43,7 +43,7 @@ public static function supportsDescribe(string $property, Metadata $metadata): b
public function describe(string $property, Metadata $metadata): array
{
$description = parent::describe($property, $metadata);
$description['type'] = Type::BUILTIN_TYPE_STRING;
$description['type'] = TypeIdentifier::STRING->value;
$description['format'] = 'string, values separated by comma';
unset($description['items']);

Expand All @@ -52,9 +52,9 @@ public function describe(string $property, Metadata $metadata): array

private function getDeserializeFunction(Metadata $metadata): \Closure
{
return match ($metadata->type) {
Type::BUILTIN_TYPE_INT => fn (string $item): int => (int) $item,
Type::BUILTIN_TYPE_FLOAT => fn (string $item): float => (float) $item,
return match ($metadata->customType) {
TypeIdentifier::INT->value => fn (string $item): int => (int) $item,
TypeIdentifier::FLOAT->value => fn (string $item): float => (float) $item,
default => fn (string $item): string => trim($item),
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/Handlers/ObjectHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function serialize(mixed $value, Metadata $metadata, SerializationContext

public static function supportsDeserialize(mixed $value, string $type): bool
{
return is_array($value) || ($value instanceof \stdClass && $type === Type::BUILTIN_TYPE_ARRAY);
return is_array($value) || ($value instanceof \stdClass && Type::BUILTIN_TYPE_ARRAY === $type);
}

/**
Expand Down
19 changes: 8 additions & 11 deletions tests/SerializeDeserializeBasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
use AnzuSystems\SerializerBundle\Tests\TestApp\Model\ExampleBackedEnum;
use AnzuSystems\SerializerBundle\Tests\TestApp\Model\ExampleUnitEnum;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\DataProvider;

final class SerializeDeserializeBasicTest extends AbstractTestCase
{
/**
* @throws SerializerException
*
* @dataProvider data
*/
#[DataProvider('data')]
public function testSerializeBasic(string $json, object $data): void
{
$serialized = $this->serializer->serialize($data);
Expand All @@ -29,9 +29,8 @@ public function testSerializeBasic(string $json, object $data): void

/**
* @throws SerializerException
*
* @dataProvider dataIgnoreNulls
*/
#[DataProvider('dataIgnoreNulls')]
public function testSerializeIgnoreNulls(string $json, object $data): void
{
$serialized = $this->serializer->serialize($data, SerializationContext::create()->setSerializeNulls(false));
Expand All @@ -40,9 +39,8 @@ public function testSerializeIgnoreNulls(string $json, object $data): void

/**
* @throws SerializerException
*
* @dataProvider data
*/
#[DataProvider('data')]
public function testDeSerializeBasic(string $json, object $data): void
{
$deserialized = $this->serializer->deserialize($json, $data::class);
Expand All @@ -51,9 +49,8 @@ public function testDeSerializeBasic(string $json, object $data): void

/**
* @throws SerializerException
*
* @dataProvider dataSerializeOnly
*/
#[DataProvider('dataSerializeOnly')]
public function testSerializeOnly(string $expectedJson, string $json, object $data): void
{
$serialized = $this->serializer->serialize($data);
Expand All @@ -64,7 +61,7 @@ public function testSerializeOnly(string $expectedJson, string $json, object $da
$this->serializer->deserialize($json, $data::class);
}

public function data(): iterable
public static function data(): iterable
{
yield [
'{"id":1,"name":"Test name","createdAt":"2023-12-31T12:34:56Z","place":"first","color":"Red"}',
Expand Down Expand Up @@ -94,7 +91,7 @@ public function data(): iterable
];
}

public function dataIgnoreNulls(): iterable
public static function dataIgnoreNulls(): iterable
{
yield [
'{"bar":123456,"baz":"bar-bar","bar-dto":{"qux":789333,"quux":"qux-qux"},"corge":"2024-05-10T00:00:00Z","garply":true}',
Expand All @@ -104,7 +101,7 @@ public function dataIgnoreNulls(): iterable
];
}

public function dataSerializeOnly(): iterable
public static function dataSerializeOnly(): iterable
{
yield [
'{"qux":789333}',
Expand Down