1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Gember\SerializerSymfony\Test; |
||
6 | |||
7 | use DateTimeImmutable; |
||
8 | use DateTimeZone; |
||
9 | use Gember\SerializerSymfony\SymfonySerializer; |
||
0 ignored issues
–
show
|
|||
10 | use Gember\SerializerSymfony\Test\TestDoubles\TestDto; |
||
0 ignored issues
–
show
The type
Gember\SerializerSymfony\Test\TestDoubles\TestDto was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
11 | use PHPUnit\Framework\Attributes\Test; |
||
0 ignored issues
–
show
The type
PHPUnit\Framework\Attributes\Test was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
12 | use PHPUnit\Framework\TestCase; |
||
13 | use Symfony\Component\Serializer\Encoder\JsonEncoder; |
||
14 | use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer; |
||
15 | use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; |
||
16 | use Symfony\Component\Serializer\Serializer; |
||
17 | |||
18 | /** |
||
19 | * @internal |
||
20 | */ |
||
21 | final class SymfonySerializerTest extends TestCase |
||
22 | { |
||
23 | private SymfonySerializer $serializer; |
||
24 | |||
25 | protected function setUp(): void |
||
26 | { |
||
27 | parent::setUp(); |
||
28 | |||
29 | $this->serializer = new SymfonySerializer( |
||
30 | new Serializer( |
||
31 | [ |
||
32 | new DateTimeNormalizer([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d\TH:i:s.uP']), |
||
33 | new ObjectNormalizer(), |
||
34 | ], |
||
35 | [ |
||
36 | new JsonEncoder(), |
||
37 | ], |
||
38 | ), |
||
39 | ); |
||
40 | } |
||
41 | |||
42 | #[Test] |
||
43 | public function itShouldSerializeObjectIntoPayload(): void |
||
44 | { |
||
45 | $serialized = $this->serializer->serialize(new TestDto( |
||
46 | 'da11f500-ab9b-49e6-96eb-83b9f3669a47', |
||
47 | 1234, |
||
48 | 23.500, |
||
49 | new DateTimeImmutable('2024-05-29 10:30:00.345654', new DateTimeZone('America/Los_Angeles')), |
||
50 | )); |
||
51 | |||
52 | self::assertSame( |
||
53 | '{"id":"da11f500-ab9b-49e6-96eb-83b9f3669a47","integer":1234,"float":23.5,"dateTimeImmutable":"2024-05-29T10:30:00.345654-07:00"}', |
||
54 | $serialized, |
||
55 | ); |
||
56 | } |
||
57 | |||
58 | #[Test] |
||
59 | public function itShouldDeserializePayloadIntoObject(): void |
||
60 | { |
||
61 | $dto = $this->serializer->deserialize( |
||
62 | '{"id":"da11f500-ab9b-49e6-96eb-83b9f3669a47","integer":1234,"float":23.5,"dateTimeImmutable":"2024-05-29T10:30:00.345654-07:00"}', |
||
63 | TestDto::class, |
||
64 | ); |
||
65 | |||
66 | self::assertEquals( |
||
67 | new TestDto( |
||
68 | 'da11f500-ab9b-49e6-96eb-83b9f3669a47', |
||
69 | 1234, |
||
70 | 23.500, |
||
71 | new DateTimeImmutable('2024-05-29 10:30:00.345654', new DateTimeZone('America/Los_Angeles')), |
||
72 | ), |
||
73 | $dto, |
||
74 | ); |
||
75 | } |
||
76 | } |
||
77 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths