|
15 | 15 | use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
|
16 | 16 | use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
|
17 | 17 | use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
|
18 |
| -use Symfony\Component\PropertyInfo\Type; |
| 18 | +use Symfony\Component\PropertyInfo\Type as LegacyType; |
19 | 19 | use Symfony\Component\Serializer\Attribute\Context;
|
20 | 20 | use Symfony\Component\Serializer\Attribute\DiscriminatorMap;
|
21 | 21 | use Symfony\Component\Serializer\Attribute\SerializedName;
|
|
56 | 56 | use Symfony\Component\Serializer\Tests\Fixtures\DummyWithObjectOrNull;
|
57 | 57 | use Symfony\Component\Serializer\Tests\Fixtures\DummyWithStringObject;
|
58 | 58 | use Symfony\Component\Serializer\Tests\Normalizer\Features\ObjectDummyWithContextAttribute;
|
| 59 | +use Symfony\Component\TypeInfo\Type; |
59 | 60 |
|
60 | 61 | class AbstractObjectNormalizerTest extends TestCase
|
61 | 62 | {
|
@@ -433,11 +434,20 @@ public function testDenormalizeCollectionDecodedFromXmlWithTwoChildren()
|
433 | 434 | private function getDenormalizerForDummyCollection()
|
434 | 435 | {
|
435 | 436 | $extractor = $this->createMock(PhpDocExtractor::class);
|
436 |
| - $extractor->method('getTypes') |
437 |
| - ->will($this->onConsecutiveCalls( |
438 |
| - [new Type('array', false, null, true, new Type('int'), new Type('object', false, DummyChild::class))], |
439 |
| - null |
440 |
| - )); |
| 437 | + |
| 438 | + if (method_exists(PhpDocExtractor::class, 'getType')) { |
| 439 | + $extractor->method('getType') |
| 440 | + ->will($this->onConsecutiveCalls( |
| 441 | + Type::list(Type::object(DummyChild::class)), |
| 442 | + null, |
| 443 | + )); |
| 444 | + } else { |
| 445 | + $extractor->method('getTypes') |
| 446 | + ->will($this->onConsecutiveCalls( |
| 447 | + [new LegacyType('array', false, null, true, new LegacyType('int'), new LegacyType('object', false, DummyChild::class))], |
| 448 | + null |
| 449 | + )); |
| 450 | + } |
441 | 451 |
|
442 | 452 | $denormalizer = new AbstractObjectNormalizerCollectionDummy(null, null, $extractor);
|
443 | 453 | $arrayDenormalizer = new ArrayDenormalizerDummy();
|
@@ -488,11 +498,20 @@ public function testDenormalizeNotSerializableObjectToPopulate()
|
488 | 498 | private function getDenormalizerForStringCollection()
|
489 | 499 | {
|
490 | 500 | $extractor = $this->createMock(PhpDocExtractor::class);
|
491 |
| - $extractor->method('getTypes') |
492 |
| - ->will($this->onConsecutiveCalls( |
493 |
| - [new Type('array', false, null, true, new Type('int'), new Type('string'))], |
494 |
| - null |
495 |
| - )); |
| 501 | + |
| 502 | + if (method_exists(PhpDocExtractor::class, 'getType')) { |
| 503 | + $extractor->method('getType') |
| 504 | + ->will($this->onConsecutiveCalls( |
| 505 | + Type::list(Type::string()), |
| 506 | + null, |
| 507 | + )); |
| 508 | + } else { |
| 509 | + $extractor->method('getTypes') |
| 510 | + ->will($this->onConsecutiveCalls( |
| 511 | + [new LegacyType('array', false, null, true, new LegacyType('int'), new LegacyType('string'))], |
| 512 | + null |
| 513 | + )); |
| 514 | + } |
496 | 515 |
|
497 | 516 | $denormalizer = new AbstractObjectNormalizerCollectionDummy(null, null, $extractor);
|
498 | 517 | $arrayDenormalizer = new ArrayDenormalizerDummy();
|
@@ -675,21 +694,40 @@ public function testDenormalizeBasicTypePropertiesFromXml()
|
675 | 694 | private function getDenormalizerForObjectWithBasicProperties()
|
676 | 695 | {
|
677 | 696 | $extractor = $this->createMock(PhpDocExtractor::class);
|
678 |
| - $extractor->method('getTypes') |
679 |
| - ->will($this->onConsecutiveCalls( |
680 |
| - [new Type('bool')], |
681 |
| - [new Type('bool')], |
682 |
| - [new Type('bool')], |
683 |
| - [new Type('bool')], |
684 |
| - [new Type('int')], |
685 |
| - [new Type('int')], |
686 |
| - [new Type('float')], |
687 |
| - [new Type('float')], |
688 |
| - [new Type('float')], |
689 |
| - [new Type('float')], |
690 |
| - [new Type('float')], |
691 |
| - [new Type('float')] |
692 |
| - )); |
| 697 | + |
| 698 | + if (method_exists(PhpDocExtractor::class, 'getType')) { |
| 699 | + $extractor->method('getType') |
| 700 | + ->will($this->onConsecutiveCalls( |
| 701 | + Type::bool(), |
| 702 | + Type::bool(), |
| 703 | + Type::bool(), |
| 704 | + Type::bool(), |
| 705 | + Type::int(), |
| 706 | + Type::int(), |
| 707 | + Type::float(), |
| 708 | + Type::float(), |
| 709 | + Type::float(), |
| 710 | + Type::float(), |
| 711 | + Type::float(), |
| 712 | + Type::float(), |
| 713 | + )); |
| 714 | + } else { |
| 715 | + $extractor->method('getTypes') |
| 716 | + ->will($this->onConsecutiveCalls( |
| 717 | + [new LegacyType('bool')], |
| 718 | + [new LegacyType('bool')], |
| 719 | + [new LegacyType('bool')], |
| 720 | + [new LegacyType('bool')], |
| 721 | + [new LegacyType('int')], |
| 722 | + [new LegacyType('int')], |
| 723 | + [new LegacyType('float')], |
| 724 | + [new LegacyType('float')], |
| 725 | + [new LegacyType('float')], |
| 726 | + [new LegacyType('float')], |
| 727 | + [new LegacyType('float')], |
| 728 | + [new LegacyType('float')] |
| 729 | + )); |
| 730 | + } |
693 | 731 |
|
694 | 732 | $denormalizer = new AbstractObjectNormalizerCollectionDummy(null, null, $extractor);
|
695 | 733 | $arrayDenormalizer = new ArrayDenormalizerDummy();
|
|
0 commit comments