|
15 | 15 | use JMS\Serializer\SerializationContext; |
16 | 16 | use JMS\Serializer\Tests\Fixtures\Author; |
17 | 17 | use JMS\Serializer\Tests\Fixtures\AuthorList; |
| 18 | +use JMS\Serializer\Tests\Fixtures\DataFalse; |
| 19 | +use JMS\Serializer\Tests\Fixtures\DataTrue; |
18 | 20 | use JMS\Serializer\Tests\Fixtures\DiscriminatedAuthor; |
19 | 21 | use JMS\Serializer\Tests\Fixtures\DiscriminatedComment; |
20 | 22 | use JMS\Serializer\Tests\Fixtures\FirstClassMapCollection; |
|
27 | 29 | use JMS\Serializer\Visitor\Factory\JsonSerializationVisitorFactory; |
28 | 30 | use JMS\Serializer\Visitor\SerializationVisitorInterface; |
29 | 31 | use PHPUnit\Framework\Attributes\DataProvider; |
| 32 | +use TypeError; |
30 | 33 |
|
31 | 34 | class JsonSerializationTest extends BaseSerializationTestCase |
32 | 35 | { |
@@ -151,6 +154,8 @@ protected static function getContent($key) |
151 | 154 | $outputs['data_float'] = '{"data":1.236}'; |
152 | 155 | $outputs['data_bool'] = '{"data":false}'; |
153 | 156 | $outputs['data_string'] = '{"data":"foo"}'; |
| 157 | + $outputs['data_true'] = '{"data":true}'; |
| 158 | + $outputs['data_false'] = '{"data":false}'; |
154 | 159 | $outputs['data_author'] = '{"data":{"full_name":"foo"}}'; |
155 | 160 | $outputs['data_comment'] = '{"data":{"author":{"full_name":"foo"},"text":"bar"}}'; |
156 | 161 | $outputs['data_discriminated_author'] = '{"data":{"full_name":"foo","objectType":"author"}}'; |
@@ -480,6 +485,50 @@ public function testSerializingUnionProperties() |
480 | 485 | self::assertEquals(static::getContent('data_string'), $serialized); |
481 | 486 | } |
482 | 487 |
|
| 488 | + public function testTrueDataType() |
| 489 | + { |
| 490 | + if (PHP_VERSION_ID < 80200) { |
| 491 | + $this->markTestSkipped('True type requires PHP 8.2'); |
| 492 | + |
| 493 | + return; |
| 494 | + } |
| 495 | + |
| 496 | + self::assertEquals( |
| 497 | + static::getContent('data_true'), |
| 498 | + $this->serialize(new DataTrue(true)), |
| 499 | + ); |
| 500 | + |
| 501 | + self::assertEquals( |
| 502 | + new DataTrue(true), |
| 503 | + $this->deserialize(static::getContent('data_true'), DataTrue::class), |
| 504 | + ); |
| 505 | + |
| 506 | + $this->expectException(TypeError::class); |
| 507 | + $this->deserialize(static::getContent('data_false'), DataTrue::class); |
| 508 | + } |
| 509 | + |
| 510 | + public function testFalseDataType() |
| 511 | + { |
| 512 | + if (PHP_VERSION_ID < 80200) { |
| 513 | + $this->markTestSkipped('False type requires PHP 8.2'); |
| 514 | + |
| 515 | + return; |
| 516 | + } |
| 517 | + |
| 518 | + self::assertEquals( |
| 519 | + static::getContent('data_false'), |
| 520 | + $this->serialize(new DataFalse(false)), |
| 521 | + ); |
| 522 | + |
| 523 | + self::assertEquals( |
| 524 | + new DataFalse(false), |
| 525 | + $this->deserialize(static::getContent('data_false'), DataFalse::class), |
| 526 | + ); |
| 527 | + |
| 528 | + $this->expectException(TypeError::class); |
| 529 | + $this->deserialize(static::getContent('data_true'), DataFalse::class); |
| 530 | + } |
| 531 | + |
483 | 532 | public function testDeserializingComplexDiscriminatedUnionProperties() |
484 | 533 | { |
485 | 534 | if (PHP_VERSION_ID < 80000) { |
|
0 commit comments