21
21
use ApiPlatform \Core \Metadata \Resource \ResourceMetadata ;
22
22
use ApiPlatform \Core \Tests \Fixtures \DummyIgnoreProperty ;
23
23
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \Dummy ;
24
+ use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \DummyCar ;
24
25
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \DummyTableInheritance ;
25
26
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \DummyTableInheritanceChild ;
26
27
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \RelatedDummy ;
@@ -56,7 +57,7 @@ public function testConstruct()
56
57
/**
57
58
* @dataProvider groupsProvider
58
59
*/
59
- public function testCreate ($ readGroups , $ writeGroups )
60
+ public function testCreate ($ readGroups , $ writeGroups, ? string $ relatedOutputClass = null )
60
61
{
61
62
$ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
62
63
$ dummyResourceMetadata = (new ResourceMetadata ())
@@ -69,6 +70,13 @@ public function testCreate($readGroups, $writeGroups)
69
70
],
70
71
]);
71
72
$ resourceMetadataFactoryProphecy ->create (Dummy::class)->willReturn ($ dummyResourceMetadata );
73
+ $ relatedDummyResourceMetadata = new ResourceMetadata ();
74
+ if ($ relatedOutputClass ) {
75
+ $ relatedDummyResourceMetadata = $ relatedDummyResourceMetadata ->withAttributes ([
76
+ 'output ' => ['class ' => $ relatedOutputClass ],
77
+ ]);
78
+ }
79
+ $ resourceMetadataFactoryProphecy ->create (RelatedDummy::class)->willReturn ($ relatedDummyResourceMetadata );
72
80
73
81
$ serializerClassMetadataFactoryProphecy = $ this ->prophesize (SerializerClassMetadataFactoryInterface::class);
74
82
$ dummySerializerClassMetadata = new SerializerClassMetadata (Dummy::class);
@@ -88,6 +96,12 @@ public function testCreate($readGroups, $writeGroups)
88
96
$ nameSerializerAttributeMetadata ->addGroup ('dummy_read ' );
89
97
$ relatedDummySerializerClassMetadata ->addAttributeMetadata ($ nameSerializerAttributeMetadata );
90
98
$ serializerClassMetadataFactoryProphecy ->getMetadataFor (RelatedDummy::class)->willReturn ($ relatedDummySerializerClassMetadata );
99
+ $ dummyCarSerializerClassMetadata = new SerializerClassMetadata (DummyCar::class);
100
+ $ nameSerializerAttributeMetadata = new SerializerAttributeMetadata ('name ' );
101
+ $ nameSerializerAttributeMetadata ->addGroup ('dummy_car_read ' );
102
+ $ nameSerializerAttributeMetadata ->addGroup ('dummy_write ' );
103
+ $ dummyCarSerializerClassMetadata ->addAttributeMetadata ($ nameSerializerAttributeMetadata );
104
+ $ serializerClassMetadataFactoryProphecy ->getMetadataFor (DummyCar::class)->willReturn ($ dummyCarSerializerClassMetadata );
91
105
92
106
$ decoratedProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
93
107
$ fooPropertyMetadata = (new PropertyMetadata ())
@@ -120,8 +134,13 @@ public function testCreate($readGroups, $writeGroups)
120
134
$ this ->assertInstanceOf (PropertyMetadata::class, $ actual [1 ]);
121
135
$ this ->assertTrue ($ actual [1 ]->isReadable ());
122
136
$ this ->assertTrue ($ actual [1 ]->isWritable ());
123
- $ this ->assertTrue ($ actual [1 ]->isReadableLink ());
124
- $ this ->assertFalse ($ actual [1 ]->isWritableLink ());
137
+ if ($ relatedOutputClass ) {
138
+ $ this ->assertFalse ($ actual [1 ]->isReadableLink ());
139
+ $ this ->assertTrue ($ actual [1 ]->isWritableLink ());
140
+ } else {
141
+ $ this ->assertTrue ($ actual [1 ]->isReadableLink ());
142
+ $ this ->assertFalse ($ actual [1 ]->isWritableLink ());
143
+ }
125
144
126
145
$ this ->assertInstanceOf (PropertyMetadata::class, $ actual [2 ]);
127
146
$ this ->assertFalse ($ actual [2 ]->isReadable ());
@@ -133,6 +152,7 @@ public function groupsProvider(): array
133
152
return [
134
153
[['dummy_read ' ], ['dummy_write ' ]],
135
154
['dummy_read ' , 'dummy_write ' ],
155
+ ['dummy_read ' , 'dummy_write ' , DummyCar::class],
136
156
];
137
157
}
138
158
0 commit comments