|
16 | 16 | use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; |
17 | 17 | use ApiPlatform\Metadata\Property\PropertyNameCollection; |
18 | 18 | use ApiPlatform\Serializer\Mapping\Loader\PropertyMetadataLoader; |
| 19 | +use ApiPlatform\Serializer\Tests\Fixtures\Model\AbstractWithDiscriminator; |
19 | 20 | use ApiPlatform\Serializer\Tests\Fixtures\Model\HasRelation; |
20 | 21 | use ApiPlatform\Serializer\Tests\Fixtures\Model\Relation; |
21 | 22 | use PHPUnit\Framework\TestCase; |
| 23 | +use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping; |
22 | 24 | use Symfony\Component\Serializer\Mapping\ClassMetadata; |
23 | 25 |
|
24 | 26 | final class PropertyMetadataLoaderTest extends TestCase |
@@ -55,4 +57,21 @@ public function testCreateMappingForAClass(): void |
55 | 57 | $this->assertArrayHasKey('name', $attributesMetadata); |
56 | 58 | $this->assertEquals(['read'], $attributesMetadata['name']->getGroups()); |
57 | 59 | } |
| 60 | + |
| 61 | + public function testForwardsDiscriminatorDefaultType(): void |
| 62 | + { |
| 63 | + if (!method_exists(ClassDiscriminatorMapping::class, 'getDefaultType')) { // @phpstan-ignore-line |
| 64 | + $this->markTestSkipped('ClassDiscriminatorMapping::getDefaultType() requires symfony/serializer 7.1+.'); |
| 65 | + } |
| 66 | + |
| 67 | + $coll = $this->createStub(PropertyNameCollectionFactoryInterface::class); |
| 68 | + $coll->method('create')->willReturn(new PropertyNameCollection([])); |
| 69 | + $loader = new PropertyMetadataLoader($coll); |
| 70 | + $classMetadata = new ClassMetadata(AbstractWithDiscriminator::class); |
| 71 | + $loader->loadClassMetadata($classMetadata); |
| 72 | + |
| 73 | + $mapping = $classMetadata->getClassDiscriminatorMapping(); |
| 74 | + $this->assertNotNull($mapping); |
| 75 | + $this->assertSame('concrete', $mapping->getDefaultType()); |
| 76 | + } |
58 | 77 | } |
0 commit comments