@@ -71,7 +71,8 @@ public function testCreate()
71
71
],
72
72
'route_name ' => 'api_dummy_entities_subresource_get_subresource ' ,
73
73
'path ' => '/dummy_entities/{id}/subresource.{_format} ' ,
74
- ],
74
+ 'operation_name ' => 'subresource_get_subresource ' ,
75
+ ] + SubresourceOperationFactory::ROUTE_OPTIONS ,
75
76
'api_dummy_entities_subresource_another_subresource_get_subresource ' => [
76
77
'property ' => 'anotherSubresource ' ,
77
78
'collection ' => false ,
@@ -83,7 +84,8 @@ public function testCreate()
83
84
],
84
85
'route_name ' => 'api_dummy_entities_subresource_another_subresource_get_subresource ' ,
85
86
'path ' => '/dummy_entities/{id}/subresource/another_subresource.{_format} ' ,
86
- ],
87
+ 'operation_name ' => 'subresource_another_subresource_get_subresource ' ,
88
+ ] + SubresourceOperationFactory::ROUTE_OPTIONS ,
87
89
'api_dummy_entities_subresource_another_subresource_subcollections_get_subresource ' => [
88
90
'property ' => 'subcollection ' ,
89
91
'collection ' => true ,
@@ -96,7 +98,8 @@ public function testCreate()
96
98
],
97
99
'route_name ' => 'api_dummy_entities_subresource_another_subresource_subcollections_get_subresource ' ,
98
100
'path ' => '/dummy_entities/{id}/subresource/another_subresource/subcollections.{_format} ' ,
99
- ],
101
+ 'operation_name ' => 'subresource_another_subresource_subcollections_get_subresource ' ,
102
+ ] + SubresourceOperationFactory::ROUTE_OPTIONS ,
100
103
'api_dummy_entities_subcollections_get_subresource ' => [
101
104
'property ' => 'subcollection ' ,
102
105
'collection ' => true ,
@@ -107,7 +110,8 @@ public function testCreate()
107
110
],
108
111
'route_name ' => 'api_dummy_entities_subcollections_get_subresource ' ,
109
112
'path ' => '/dummy_entities/{id}/subcollections.{_format} ' ,
110
- ],
113
+ 'operation_name ' => 'subcollections_get_subresource ' ,
114
+ ] + SubresourceOperationFactory::ROUTE_OPTIONS ,
111
115
'api_dummy_entities_subcollections_another_subresource_get_subresource ' => [
112
116
'property ' => 'anotherSubresource ' ,
113
117
'collection ' => false ,
@@ -119,7 +123,8 @@ public function testCreate()
119
123
],
120
124
'route_name ' => 'api_dummy_entities_subcollections_another_subresource_get_subresource ' ,
121
125
'path ' => '/dummy_entities/{id}/subcollections/{subcollection}/another_subresource.{_format} ' ,
122
- ],
126
+ 'operation_name ' => 'subcollections_another_subresource_get_subresource ' ,
127
+ ] + SubresourceOperationFactory::ROUTE_OPTIONS ,
123
128
'api_dummy_entities_subcollections_another_subresource_subresource_get_subresource ' => [
124
129
'property ' => 'subresource ' ,
125
130
'collection ' => false ,
@@ -132,7 +137,123 @@ public function testCreate()
132
137
],
133
138
'route_name ' => 'api_dummy_entities_subcollections_another_subresource_subresource_get_subresource ' ,
134
139
'path ' => '/dummy_entities/{id}/subcollections/{subcollection}/another_subresource/subresource.{_format} ' ,
140
+ 'operation_name ' => 'subcollections_another_subresource_subresource_get_subresource ' ,
141
+ ] + SubresourceOperationFactory::ROUTE_OPTIONS ,
142
+ ], $ subresourceOperationFactory ->create (DummyEntity::class));
143
+ }
144
+
145
+ public function testCreateByOverriding ()
146
+ {
147
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
148
+ $ resourceMetadataFactoryProphecy ->create (RelatedDummyEntity::class)->shouldBeCalled ()->willReturn (new ResourceMetadata ('relatedDummyEntity ' ));
149
+ $ resourceMetadataFactoryProphecy ->create (DummyEntity::class)->shouldBeCalled ()->willReturn ((new ResourceMetadata ('dummyEntity ' ))->withCollectionOperations ([
150
+ 'subcollections_get_subresource ' => [
151
+ 'path ' => '/dummy_entities/{id}/foobars ' ,
135
152
],
153
+ ]));
154
+
155
+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
156
+ $ propertyNameCollectionFactoryProphecy ->create (DummyEntity::class)->shouldBeCalled ()->willReturn (new PropertyNameCollection (['foo ' , 'subresource ' , 'subcollection ' ]));
157
+ $ propertyNameCollectionFactoryProphecy ->create (RelatedDummyEntity::class)->shouldBeCalled ()->willReturn (new PropertyNameCollection (['bar ' , 'anotherSubresource ' ]));
158
+
159
+ $ subresourceMetadata = (new PropertyMetadata ())->withSubresource (new SubresourceMetadata (RelatedDummyEntity::class));
160
+ $ subresourceMetadataCollection = (new PropertyMetadata ())->withSubresource (new SubresourceMetadata (RelatedDummyEntity::class, true ));
161
+ $ anotherSubresourceMetadata = (new PropertyMetadata ())->withSubresource (new SubresourceMetadata (DummyEntity::class, false ));
162
+
163
+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
164
+ $ propertyMetadataFactoryProphecy ->create (DummyEntity::class, 'foo ' )->shouldBeCalled ()->willReturn (new PropertyMetadata ());
165
+ $ propertyMetadataFactoryProphecy ->create (DummyEntity::class, 'subresource ' )->shouldBeCalled ()->willReturn ($ subresourceMetadata );
166
+ $ propertyMetadataFactoryProphecy ->create (DummyEntity::class, 'subcollection ' )->shouldBeCalled ()->willReturn ($ subresourceMetadataCollection );
167
+ $ propertyMetadataFactoryProphecy ->create (RelatedDummyEntity::class, 'bar ' )->shouldBeCalled ()->willReturn (new PropertyMetadata ());
168
+ $ propertyMetadataFactoryProphecy ->create (RelatedDummyEntity::class, 'anotherSubresource ' )->shouldBeCalled ()->willReturn ($ anotherSubresourceMetadata );
169
+
170
+ $ pathSegmentNameGeneratorProphecy = $ this ->prophesize (PathSegmentNameGeneratorInterface::class);
171
+ $ pathSegmentNameGeneratorProphecy ->getSegmentName ('subresource ' , false )->shouldBeCalled ()->willReturn ('subresource ' );
172
+ $ pathSegmentNameGeneratorProphecy ->getSegmentName ('subcollection ' , true )->shouldBeCalled ()->willReturn ('subcollections ' );
173
+ $ pathSegmentNameGeneratorProphecy ->getSegmentName ('dummyEntity ' , true )->shouldBeCalled ()->willReturn ('dummy_entities ' );
174
+ $ pathSegmentNameGeneratorProphecy ->getSegmentName ('anotherSubresource ' , false )->shouldBeCalled ()->willReturn ('another_subresource ' );
175
+
176
+ $ subresourceOperationFactory = new SubresourceOperationFactory ($ resourceMetadataFactoryProphecy ->reveal (), $ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ pathSegmentNameGeneratorProphecy ->reveal ());
177
+
178
+ $ this ->assertEquals ([
179
+ 'api_dummy_entities_subresource_get_subresource ' => [
180
+ 'property ' => 'subresource ' ,
181
+ 'collection ' => false ,
182
+ 'resource_class ' => RelatedDummyEntity::class,
183
+ 'shortNames ' => ['relatedDummyEntity ' , 'dummyEntity ' ],
184
+ 'identifiers ' => [
185
+ ['id ' , DummyEntity::class, true ],
186
+ ],
187
+ 'route_name ' => 'api_dummy_entities_subresource_get_subresource ' ,
188
+ 'path ' => '/dummy_entities/{id}/subresource.{_format} ' ,
189
+ 'operation_name ' => 'subresource_get_subresource ' ,
190
+ ] + SubresourceOperationFactory::ROUTE_OPTIONS ,
191
+ 'api_dummy_entities_subresource_another_subresource_get_subresource ' => [
192
+ 'property ' => 'anotherSubresource ' ,
193
+ 'collection ' => false ,
194
+ 'resource_class ' => DummyEntity::class,
195
+ 'shortNames ' => ['dummyEntity ' , 'relatedDummyEntity ' ],
196
+ 'identifiers ' => [
197
+ ['id ' , DummyEntity::class, true ],
198
+ ['subresource ' , RelatedDummyEntity::class, false ],
199
+ ],
200
+ 'route_name ' => 'api_dummy_entities_subresource_another_subresource_get_subresource ' ,
201
+ 'path ' => '/dummy_entities/{id}/subresource/another_subresource.{_format} ' ,
202
+ 'operation_name ' => 'subresource_another_subresource_get_subresource ' ,
203
+ ] + SubresourceOperationFactory::ROUTE_OPTIONS ,
204
+ 'api_dummy_entities_subresource_another_subresource_subcollections_get_subresource ' => [
205
+ 'property ' => 'subcollection ' ,
206
+ 'collection ' => true ,
207
+ 'resource_class ' => RelatedDummyEntity::class,
208
+ 'shortNames ' => ['relatedDummyEntity ' , 'dummyEntity ' ],
209
+ 'identifiers ' => [
210
+ ['id ' , DummyEntity::class, true ],
211
+ ['subresource ' , RelatedDummyEntity::class, false ],
212
+ ['anotherSubresource ' , DummyEntity::class, false ],
213
+ ],
214
+ 'route_name ' => 'api_dummy_entities_subresource_another_subresource_subcollections_get_subresource ' ,
215
+ 'path ' => '/dummy_entities/{id}/subresource/another_subresource/subcollections.{_format} ' ,
216
+ 'operation_name ' => 'subresource_another_subresource_subcollections_get_subresource ' ,
217
+ ] + SubresourceOperationFactory::ROUTE_OPTIONS ,
218
+ 'api_dummy_entities_subcollections_get_subresource ' => [
219
+ 'property ' => 'subcollection ' ,
220
+ 'collection ' => true ,
221
+ 'resource_class ' => RelatedDummyEntity::class,
222
+ 'shortNames ' => ['relatedDummyEntity ' , 'dummyEntity ' ],
223
+ 'identifiers ' => [
224
+ ['id ' , DummyEntity::class, true ],
225
+ ],
226
+ 'route_name ' => 'api_dummy_entities_subcollections_get_subresource ' ,
227
+ 'path ' => '/dummy_entities/{id}/foobars ' ,
228
+ 'operation_name ' => 'subcollections_get_subresource ' ,
229
+ ] + SubresourceOperationFactory::ROUTE_OPTIONS ,
230
+ 'api_dummy_entities_subcollections_another_subresource_get_subresource ' => [
231
+ 'property ' => 'anotherSubresource ' ,
232
+ 'collection ' => false ,
233
+ 'resource_class ' => DummyEntity::class,
234
+ 'shortNames ' => ['dummyEntity ' , 'relatedDummyEntity ' ],
235
+ 'identifiers ' => [
236
+ ['id ' , DummyEntity::class, true ],
237
+ ['subcollection ' , RelatedDummyEntity::class, true ],
238
+ ],
239
+ 'route_name ' => 'api_dummy_entities_subcollections_another_subresource_get_subresource ' ,
240
+ 'path ' => '/dummy_entities/{id}/foobars/{subcollection}/another_subresource.{_format} ' ,
241
+ 'operation_name ' => 'subcollections_another_subresource_get_subresource ' ,
242
+ ] + SubresourceOperationFactory::ROUTE_OPTIONS ,
243
+ 'api_dummy_entities_subcollections_another_subresource_subresource_get_subresource ' => [
244
+ 'property ' => 'subresource ' ,
245
+ 'collection ' => false ,
246
+ 'resource_class ' => RelatedDummyEntity::class,
247
+ 'shortNames ' => ['relatedDummyEntity ' , 'dummyEntity ' ],
248
+ 'identifiers ' => [
249
+ ['id ' , DummyEntity::class, true ],
250
+ ['subcollection ' , RelatedDummyEntity::class, true ],
251
+ ['anotherSubresource ' , DummyEntity::class, false ],
252
+ ],
253
+ 'route_name ' => 'api_dummy_entities_subcollections_another_subresource_subresource_get_subresource ' ,
254
+ 'path ' => '/dummy_entities/{id}/foobars/{subcollection}/another_subresource/subresource.{_format} ' ,
255
+ 'operation_name ' => 'subcollections_another_subresource_subresource_get_subresource ' ,
256
+ ] + SubresourceOperationFactory::ROUTE_OPTIONS ,
136
257
], $ subresourceOperationFactory ->create (DummyEntity::class));
137
258
}
138
259
}
0 commit comments