1717use ApiPlatform \Core \Metadata \Property \Factory \PropertyMetadataFactoryInterface ;
1818use ApiPlatform \Core \Metadata \Property \PropertyMetadata ;
1919use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \Dummy ;
20+ use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \DummyPropertyWithDefaultValue ;
2021use Doctrine \Common \Persistence \ManagerRegistry ;
2122use Doctrine \Common \Persistence \Mapping \ClassMetadata ;
2223use Doctrine \Common \Persistence \ObjectManager ;
@@ -73,6 +74,7 @@ public function testCreateIsWritable()
7374
7475 $ classMetadata = $ this ->prophesize (ClassMetadataInfo::class);
7576 $ classMetadata ->getIdentifier ()->shouldBeCalled ()->willReturn (['id ' ]);
77+ $ classMetadata ->getFieldNames ()->shouldBeCalled ()->willReturn ([]);
7678
7779 $ objectManager = $ this ->prophesize (ObjectManager::class);
7880 $ objectManager ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadata ->reveal ());
@@ -88,6 +90,31 @@ public function testCreateIsWritable()
8890 $ this ->assertEquals ($ doctrinePropertyMetadata ->isWritable (), false );
8991 }
9092
93+ public function testCreateWithDefaultOption ()
94+ {
95+ $ propertyMetadata = new PropertyMetadata ();
96+
97+ $ propertyMetadataFactory = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
98+ $ propertyMetadataFactory ->create (DummyPropertyWithDefaultValue::class, 'dummyDefaultOption ' , [])->shouldBeCalled ()->willReturn ($ propertyMetadata );
99+
100+ $ classMetadata = new ClassMetadataInfo (DummyPropertyWithDefaultValue::class);
101+ $ classMetadata ->fieldMappings = [
102+ 'dummyDefaultOption ' => ['options ' => ['default ' => 'default value ' ]],
103+ ];
104+
105+ $ objectManager = $ this ->prophesize (ObjectManager::class);
106+ $ objectManager ->getClassMetadata (DummyPropertyWithDefaultValue::class)->shouldBeCalled ()->willReturn ($ classMetadata );
107+
108+ $ managerRegistry = $ this ->prophesize (ManagerRegistry::class);
109+ $ managerRegistry ->getManagerForClass (DummyPropertyWithDefaultValue::class)->shouldBeCalled ()->willReturn ($ objectManager ->reveal ());
110+
111+ $ doctrineOrmPropertyMetadataFactory = new DoctrineOrmPropertyMetadataFactory ($ managerRegistry ->reveal (), $ propertyMetadataFactory ->reveal ());
112+
113+ $ doctrinePropertyMetadata = $ doctrineOrmPropertyMetadataFactory ->create (DummyPropertyWithDefaultValue::class, 'dummyDefaultOption ' );
114+
115+ $ this ->assertEquals ($ doctrinePropertyMetadata ->getDefault (), 'default value ' );
116+ }
117+
91118 public function testCreateClassMetadataInfo ()
92119 {
93120 $ propertyMetadata = new PropertyMetadata ();
@@ -98,6 +125,7 @@ public function testCreateClassMetadataInfo()
98125 $ classMetadata = $ this ->prophesize (ClassMetadataInfo::class);
99126 $ classMetadata ->getIdentifier ()->shouldBeCalled ()->willReturn (['id ' ]);
100127 $ classMetadata ->isIdentifierNatural ()->shouldBeCalled ()->willReturn (true );
128+ $ classMetadata ->getFieldNames ()->shouldBeCalled ()->willReturn ([]);
101129
102130 $ objectManager = $ this ->prophesize (ObjectManager::class);
103131 $ objectManager ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadata ->reveal ());
0 commit comments