|
18 | 18 | use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; |
19 | 19 | use Symfony\Component\Serializer\Encoder\JsonEncoder; |
20 | 20 | use Symfony\Component\Serializer\Exception\InvalidArgumentException; |
| 21 | +use Symfony\Component\Serializer\Exception\LogicException; |
21 | 22 | use Symfony\Component\Serializer\Exception\NotNormalizableValueException; |
22 | 23 | use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata; |
23 | 24 | use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping; |
@@ -558,51 +559,52 @@ public function testNormalizeScalarArray() |
558 | 559 |
|
559 | 560 | public function testDeserializeScalar() |
560 | 561 | { |
561 | | - $serializer = new Serializer([new ScalarDenormalizer()], ['json' => new JsonEncoder()]); |
| 562 | + $serializer = new Serializer([], ['json' => new JsonEncoder()]); |
562 | 563 |
|
563 | 564 | $this->assertSame(42, $serializer->deserialize('42', 'int', 'json')); |
564 | 565 | $this->assertTrue($serializer->deserialize('true', 'bool', 'json')); |
565 | 566 | $this->assertSame(3.14, $serializer->deserialize('3.14', 'float', 'json')); |
566 | 567 | $this->assertSame(3.14, $serializer->deserialize('31.4e-1', 'float', 'json')); |
567 | | - $this->assertSame(3.0, $serializer->deserialize('3', 'float', 'json')); // '3' === json_encode(3.0) |
568 | 568 | $this->assertSame(' spaces ', $serializer->deserialize('" spaces "', 'string', 'json')); |
569 | 569 | $this->assertSame('@Ca$e%', $serializer->deserialize('"@Ca$e%"', 'string', 'json')); |
| 570 | + |
| 571 | + // Only works with the ScalarDenormalizer |
| 572 | + $serializer = new Serializer([new ScalarDenormalizer()], ['json' => new JsonEncoder()]); |
| 573 | + |
| 574 | + $this->assertSame(3.0, $serializer->deserialize('3', 'float', 'json')); // '3' === json_encode(3.0) |
570 | 575 | } |
571 | 576 |
|
572 | 577 | public function testDeserializeLegacyScalarType() |
573 | 578 | { |
574 | | - $this->expectException(NotNormalizableValueException::class); |
575 | | - $serializer = new Serializer([new ScalarDenormalizer()], ['json' => new JsonEncoder()]); |
| 579 | + $this->expectException(LogicException::class); |
| 580 | + $serializer = new Serializer([], ['json' => new JsonEncoder()]); |
576 | 581 | $serializer->deserialize('42', 'integer', 'json'); |
577 | 582 | } |
578 | 583 |
|
579 | 584 | public function testDeserializeScalarTypeToCustomType() |
580 | 585 | { |
581 | | - $this->expectException(NotNormalizableValueException::class); |
582 | | - $serializer = new Serializer([new ScalarDenormalizer()], ['json' => new JsonEncoder()]); |
| 586 | + $this->expectException(LogicException::class); |
| 587 | + $serializer = new Serializer([], ['json' => new JsonEncoder()]); |
583 | 588 | $serializer->deserialize('"something"', Foo::class, 'json'); |
584 | 589 | } |
585 | 590 |
|
586 | 591 | public function testDeserializeNonscalarTypeToScalar() |
587 | 592 | { |
588 | | - $this->expectException(InvalidArgumentException::class); |
589 | | - $serializer = new Serializer([new ScalarDenormalizer()], ['json' => new JsonEncoder()]); |
| 593 | + $this->expectException(NotNormalizableValueException::class); |
| 594 | + $serializer = new Serializer([], ['json' => new JsonEncoder()]); |
590 | 595 | $serializer->deserialize('{"foo":true}', 'string', 'json'); |
591 | 596 | } |
592 | 597 |
|
593 | 598 | public function testDeserializeInconsistentScalarType() |
594 | 599 | { |
595 | 600 | $this->expectException(NotNormalizableValueException::class); |
596 | | - $serializer = new Serializer([new ScalarDenormalizer()], ['json' => new JsonEncoder()]); |
| 601 | + $serializer = new Serializer([], ['json' => new JsonEncoder()]); |
597 | 602 | $serializer->deserialize('"42"', 'int', 'json'); |
598 | 603 | } |
599 | 604 |
|
600 | 605 | public function testDeserializeScalarArray() |
601 | 606 | { |
602 | | - $serializer = new Serializer([ |
603 | | - new ScalarDenormalizer(), |
604 | | - new ArrayDenormalizer(), |
605 | | - ], ['json' => new JsonEncoder()]); |
| 607 | + $serializer = new Serializer([new ArrayDenormalizer()], ['json' => new JsonEncoder()]); |
606 | 608 |
|
607 | 609 | $this->assertSame([42], $serializer->deserialize('[42]', 'int[]', 'json')); |
608 | 610 | $this->assertSame([true, false], $serializer->deserialize('[true,false]', 'bool[]', 'json')); |
|
0 commit comments