|
19 | 19 | use ApiPlatform\Metadata\ApiProperty; |
20 | 20 | use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; |
21 | 21 | use Doctrine\ORM\Mapping\ClassMetadata as ORMClassMetadata; |
| 22 | +use Doctrine\ORM\Mapping\Driver\AttributeDriver; |
22 | 23 | use Doctrine\ORM\Mapping\FieldMapping; |
23 | 24 | use Doctrine\Persistence\ManagerRegistry; |
24 | 25 | use Doctrine\Persistence\Mapping\ClassMetadata; |
| 26 | +use Doctrine\Persistence\Mapping\RuntimeReflectionService; |
25 | 27 | use Doctrine\Persistence\ObjectManager; |
26 | 28 | use PHPUnit\Framework\TestCase; |
27 | 29 | use Prophecy\PhpUnit\ProphecyTrait; |
@@ -126,6 +128,26 @@ public function testCreateWithDefaultOption(): void |
126 | 128 | $this->assertSame($doctrinePropertyMetadata->getDefault(), 'default value'); |
127 | 129 | } |
128 | 130 |
|
| 131 | + public function testCreateWithDefaultOptionFromColumnAttribute(): void |
| 132 | + { |
| 133 | + $classMetadata = new ORMClassMetadata(DummyPropertyWithDefaultValue::class); |
| 134 | + $classMetadata->initializeReflection(new RuntimeReflectionService()); |
| 135 | + (new AttributeDriver([]))->loadMetadataForClass(DummyPropertyWithDefaultValue::class, $classMetadata); |
| 136 | + |
| 137 | + $propertyMetadataFactory = $this->createStub(PropertyMetadataFactoryInterface::class); |
| 138 | + $propertyMetadataFactory->method('create')->willReturn(new ApiProperty()); |
| 139 | + |
| 140 | + $objectManager = $this->createStub(ObjectManager::class); |
| 141 | + $objectManager->method('getClassMetadata')->willReturn($classMetadata); |
| 142 | + |
| 143 | + $managerRegistry = $this->createStub(ManagerRegistry::class); |
| 144 | + $managerRegistry->method('getManagerForClass')->willReturn($objectManager); |
| 145 | + |
| 146 | + $doctrineOrmPropertyMetadataFactory = new DoctrineOrmPropertyMetadataFactory($managerRegistry, $propertyMetadataFactory); |
| 147 | + |
| 148 | + $this->assertSame('default value', $doctrineOrmPropertyMetadataFactory->create(DummyPropertyWithDefaultValue::class, 'dummyDefaultOption')->getDefault()); |
| 149 | + } |
| 150 | + |
129 | 151 | public function testCreateClassMetadataInfo(): void |
130 | 152 | { |
131 | 153 | $propertyMetadata = new ApiProperty(); |
|
0 commit comments