17
17
use ApiPlatform \Core \Metadata \Property \Factory \PropertyMetadataFactoryInterface ;
18
18
use ApiPlatform \Core \Metadata \Property \PropertyMetadata ;
19
19
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \Dummy ;
20
+ use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \DummyPropertyWithDefaultValue ;
20
21
use Doctrine \Common \Persistence \ManagerRegistry ;
21
22
use Doctrine \Common \Persistence \Mapping \ClassMetadata ;
22
23
use Doctrine \Common \Persistence \ObjectManager ;
@@ -73,6 +74,7 @@ public function testCreateIsWritable()
73
74
74
75
$ classMetadata = $ this ->prophesize (ClassMetadataInfo::class);
75
76
$ classMetadata ->getIdentifier ()->shouldBeCalled ()->willReturn (['id ' ]);
77
+ $ classMetadata ->getFieldNames ()->shouldBeCalled ()->willReturn ([]);
76
78
77
79
$ objectManager = $ this ->prophesize (ObjectManager::class);
78
80
$ objectManager ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadata ->reveal ());
@@ -88,6 +90,31 @@ public function testCreateIsWritable()
88
90
$ this ->assertEquals ($ doctrinePropertyMetadata ->isWritable (), false );
89
91
}
90
92
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
+
91
118
public function testCreateClassMetadataInfo ()
92
119
{
93
120
$ propertyMetadata = new PropertyMetadata ();
@@ -98,6 +125,7 @@ public function testCreateClassMetadataInfo()
98
125
$ classMetadata = $ this ->prophesize (ClassMetadataInfo::class);
99
126
$ classMetadata ->getIdentifier ()->shouldBeCalled ()->willReturn (['id ' ]);
100
127
$ classMetadata ->isIdentifierNatural ()->shouldBeCalled ()->willReturn (true );
128
+ $ classMetadata ->getFieldNames ()->shouldBeCalled ()->willReturn ([]);
101
129
102
130
$ objectManager = $ this ->prophesize (ObjectManager::class);
103
131
$ objectManager ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadata ->reveal ());
0 commit comments