1919use ApiPlatform \Metadata \ApiProperty ;
2020use ApiPlatform \Metadata \Property \Factory \PropertyMetadataFactoryInterface ;
2121use Doctrine \ORM \Mapping \ClassMetadata as ORMClassMetadata ;
22+ use Doctrine \ORM \Mapping \Driver \AttributeDriver ;
2223use Doctrine \ORM \Mapping \FieldMapping ;
2324use Doctrine \Persistence \ManagerRegistry ;
2425use Doctrine \Persistence \Mapping \ClassMetadata ;
26+ use Doctrine \Persistence \Mapping \RuntimeReflectionService ;
2527use Doctrine \Persistence \ObjectManager ;
2628use PHPUnit \Framework \TestCase ;
2729use Prophecy \PhpUnit \ProphecyTrait ;
@@ -106,6 +108,7 @@ public function testCreateWithDefaultOption(): void
106108 $ classMetadata ->getFieldNames ()->shouldBeCalled ()->willReturn (['dummyDefaultOption ' ]);
107109 if (class_exists (FieldMapping::class)) {
108110 $ fieldMapping = new FieldMapping ('string ' , 'dummyDefaultOption ' , 'dummyDefaultOption ' );
111+ // TODO: FieldMapping::$default is removed in doctrine/orm 4.0, use $fieldMapping->options = ['default' => 'default value'] instead
109112 $ fieldMapping ->default = 'default value ' ;
110113 $ classMetadata ->fieldMappings = [$ fieldMapping ];
111114 $ classMetadata ->getFieldMapping ('dummyDefaultOption ' )->willReturn ($ fieldMapping );
@@ -126,6 +129,26 @@ public function testCreateWithDefaultOption(): void
126129 $ this ->assertSame ($ doctrinePropertyMetadata ->getDefault (), 'default value ' );
127130 }
128131
132+ public function testCreateWithDefaultOptionFromColumnAttribute (): void
133+ {
134+ $ classMetadata = new ORMClassMetadata (DummyPropertyWithDefaultValue::class);
135+ $ classMetadata ->initializeReflection (new RuntimeReflectionService ());
136+ (new AttributeDriver ([]))->loadMetadataForClass (DummyPropertyWithDefaultValue::class, $ classMetadata );
137+
138+ $ propertyMetadataFactory = $ this ->createStub (PropertyMetadataFactoryInterface::class);
139+ $ propertyMetadataFactory ->method ('create ' )->willReturn (new ApiProperty ());
140+
141+ $ objectManager = $ this ->createStub (ObjectManager::class);
142+ $ objectManager ->method ('getClassMetadata ' )->willReturn ($ classMetadata );
143+
144+ $ managerRegistry = $ this ->createStub (ManagerRegistry::class);
145+ $ managerRegistry ->method ('getManagerForClass ' )->willReturn ($ objectManager );
146+
147+ $ doctrineOrmPropertyMetadataFactory = new DoctrineOrmPropertyMetadataFactory ($ managerRegistry , $ propertyMetadataFactory );
148+
149+ $ this ->assertSame ('default value ' , $ doctrineOrmPropertyMetadataFactory ->create (DummyPropertyWithDefaultValue::class, 'dummyDefaultOption ' )->getDefault ());
150+ }
151+
129152 public function testCreateClassMetadataInfo (): void
130153 {
131154 $ propertyMetadata = new ApiProperty ();
0 commit comments