|
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;
|
@@ -556,61 +557,62 @@ public function testNormalizeScalarArray()
|
556 | 557 | $this->assertSame('[" spaces ","@Ca$e%"]', $serializer->serialize([' spaces ', '@Ca$e%'], 'json'));
|
557 | 558 | }
|
558 | 559 |
|
559 |
| - public function testDeserializeScalar() |
| 560 | + public function testLegacyDeserializeScalar() |
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 |
| - public function testDeserializeNonscalarTypeToScalar() |
| 591 | + public function testLegacyDeserializeNonscalarTypeToScalar() |
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 |
| - public function testDeserializeInconsistentScalarType() |
| 598 | + public function testLegacyDeserializeInconsistentScalarType() |
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 |
| - public function testDeserializeScalarArray() |
| 605 | + public function testLegacyDeserializeScalarArray() |
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'));
|
609 | 611 | $this->assertSame([3.14, 3.24], $serializer->deserialize('[3.14,32.4e-1]', 'float[]', 'json'));
|
610 | 612 | $this->assertSame([' spaces ', '@Ca$e%'], $serializer->deserialize('[" spaces ","@Ca$e%"]', 'string[]', 'json'));
|
611 | 613 | }
|
612 | 614 |
|
613 |
| - public function testDeserializeInconsistentScalarArray() |
| 615 | + public function testLegacyDeserializeInconsistentScalarArray() |
614 | 616 | {
|
615 | 617 | $this->expectException(NotNormalizableValueException::class);
|
616 | 618 | $serializer = new Serializer([new ArrayDenormalizer()], ['json' => new JsonEncoder()]);
|
|
0 commit comments