@@ -67,6 +67,63 @@ public function testSupports()
67
67
]));
68
68
}
69
69
70
+ public function testSupportsAttributeNormalization ()
71
+ {
72
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
73
+ $ resourceMetadataFactoryProphecy ->create (CustomAttributeDummy::class)->willReturn (new ResourceMetadata ('dummy ' , 'dummy ' , null , [
74
+ 'get ' => ['method ' => 'GET ' , 'normalization_context ' => ['groups ' => ['custom_attr_dummy_get ' ]]],
75
+ 'put ' => ['method ' => 'PUT ' , 'denormalization_context ' => ['groups ' => ['custom_attr_dummy_put ' ]]],
76
+ 'delete ' => ['method ' => 'DELETE ' ],
77
+ ], []))->shouldBeCalled ();
78
+ $ resourceMetadataFactory = $ resourceMetadataFactoryProphecy ->reveal ();
79
+
80
+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
81
+ $ propertyNameCollectionFactoryProphecy ->create (CustomAttributeDummy::class, Argument::cetera ())->willReturn (new PropertyNameCollection ([
82
+ 'id ' ,
83
+ 'name ' ,
84
+ ]))->shouldBeCalled ();
85
+ $ propertyNameCollectionFactory = $ propertyNameCollectionFactoryProphecy ->reveal ();
86
+
87
+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
88
+ $ idPropertyMetadata = (new PropertyMetadata ())
89
+ ->withType (new Type (Type::BUILTIN_TYPE_INT , false ))
90
+ ->withDescription ('The id. ' )
91
+ ->withReadable (true )
92
+ ->withWritable (false )
93
+ ->withRequired (true );
94
+ $ propertyMetadataFactoryProphecy ->create (CustomAttributeDummy::class, 'id ' )->willReturn ($ idPropertyMetadata )->shouldBeCalled ();
95
+ $ namePropertyMetadata = (new PropertyMetadata ())
96
+ ->withType (new Type (Type::BUILTIN_TYPE_STRING , false ))
97
+ ->withDescription ('The dummy name. ' )
98
+ ->withReadable (true )
99
+ ->withWritable (true )
100
+ ->withRequired (true );
101
+ $ propertyMetadataFactoryProphecy ->create (CustomAttributeDummy::class, 'name ' )->willReturn ($ namePropertyMetadata )->shouldBeCalled ();
102
+
103
+ $ propertyMetadataFactory = $ propertyMetadataFactoryProphecy ->reveal ();
104
+
105
+ $ apiPlatformParser = new ApiPlatformParser ($ resourceMetadataFactory , $ propertyNameCollectionFactory , $ propertyMetadataFactory );
106
+
107
+ $ actual = $ apiPlatformParser ->parse ([
108
+ 'class ' => sprintf ('%s:%s:%s ' , ApiPlatformParser::OUT_PREFIX , CustomAttributeDummy::class, 'get ' ),
109
+ ]);
110
+
111
+ $ this ->assertEquals ([
112
+ 'id ' => [
113
+ 'dataType ' => DataTypes::INTEGER ,
114
+ 'required ' => true ,
115
+ 'description ' => 'The id. ' ,
116
+ 'readonly ' => true ,
117
+ ],
118
+ 'name ' => [
119
+ 'dataType ' => DataTypes::STRING ,
120
+ 'required ' => true ,
121
+ 'description ' => 'The dummy name. ' ,
122
+ 'readonly ' => false ,
123
+ ],
124
+ ], $ actual );
125
+ }
126
+
70
127
public function testSupportsUnknownResource ()
71
128
{
72
129
$ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
@@ -108,7 +165,12 @@ public function testSupportsUnsupportedClassFormat()
108
165
public function testParse ()
109
166
{
110
167
$ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
111
- $ resourceMetadataFactoryProphecy ->create (Dummy::class)->willReturn (new ResourceMetadata ())->shouldBeCalled ();
168
+ $ resourceMetadataFactoryProphecy ->create (Dummy::class)->willReturn (new ResourceMetadata ('dummy ' , 'dummy ' , null , [
169
+ 'get ' => ['method ' => 'GET ' , 'normalization_context ' => ['groups ' => ['custom_attr_dummy_get ' ]]],
170
+ 'put ' => ['method ' => 'PUT ' , 'denormalization_context ' => ['groups ' => ['custom_attr_dummy_put ' ]]],
171
+ 'gerard ' => ['method ' => 'get ' , 'path ' => '/gerard ' , 'denormalization_context ' => ['groups ' => ['custom_attr_dummy_put ' ]]],
172
+ 'delete ' => ['method ' => 'DELETE ' ],
173
+ ], []))->shouldBeCalled ();
112
174
$ resourceMetadataFactory = $ resourceMetadataFactoryProphecy ->reveal ();
113
175
114
176
$ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
@@ -146,7 +208,7 @@ public function testParse()
146
208
$ apiPlatformParser = new ApiPlatformParser ($ resourceMetadataFactory , $ propertyNameCollectionFactory , $ propertyMetadataFactory );
147
209
148
210
$ actual = $ apiPlatformParser ->parse ([
149
- 'class ' => sprintf ('%s:%s ' , ApiPlatformParser::OUT_PREFIX , Dummy::class),
211
+ 'class ' => sprintf ('%s:%s:%s ' , ApiPlatformParser::OUT_PREFIX , Dummy::class, ' gerard ' ),
150
212
]);
151
213
152
214
$ this ->assertEquals ([
@@ -174,7 +236,7 @@ public function testParse()
174
236
public function testParseDateTime ()
175
237
{
176
238
$ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
177
- $ resourceMetadataFactoryProphecy ->create (Dummy::class)->willReturn (new ResourceMetadata ())->shouldBeCalled ();
239
+ $ resourceMetadataFactoryProphecy ->create (Dummy::class)->willReturn (new ResourceMetadata (' dummy ' , ' dummy ' , null , [], [] ))->shouldBeCalled ();
178
240
$ resourceMetadataFactory = $ resourceMetadataFactoryProphecy ->reveal ();
179
241
180
242
$ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
@@ -196,7 +258,7 @@ public function testParseDateTime()
196
258
$ apiPlatformParser = new ApiPlatformParser ($ resourceMetadataFactory , $ propertyNameCollectionFactory , $ propertyMetadataFactory );
197
259
198
260
$ actual = $ apiPlatformParser ->parse ([
199
- 'class ' => sprintf ('%s:%s ' , ApiPlatformParser::OUT_PREFIX , Dummy::class),
261
+ 'class ' => sprintf ('%s:%s:%s ' , ApiPlatformParser::OUT_PREFIX , Dummy::class, ' get ' ),
200
262
]);
201
263
202
264
$ this ->assertEquals ([
@@ -213,7 +275,7 @@ public function testParseDateTime()
213
275
public function testParseRelation ()
214
276
{
215
277
$ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
216
- $ resourceMetadataFactoryProphecy ->create (Dummy::class)->willReturn (new ResourceMetadata ())->shouldBeCalled ();
278
+ $ resourceMetadataFactoryProphecy ->create (Dummy::class)->willReturn (new ResourceMetadata (' dummy ' , ' dummy ' , null , [], [] ))->shouldBeCalled ();
217
279
$ resourceMetadataFactoryProphecy ->create (RelatedDummy::class)->willReturn (new ResourceMetadata ())->shouldBeCalled ();
218
280
$ resourceMetadataFactory = $ resourceMetadataFactoryProphecy ->reveal ();
219
281
@@ -262,7 +324,7 @@ public function testParseRelation()
262
324
$ apiPlatformParser = new ApiPlatformParser ($ resourceMetadataFactory , $ propertyNameCollectionFactory , $ propertyMetadataFactory );
263
325
264
326
$ actual = $ apiPlatformParser ->parse ([
265
- 'class ' => sprintf ('%s:%s ' , ApiPlatformParser::OUT_PREFIX , Dummy::class),
327
+ 'class ' => sprintf ('%s:%s:%s ' , ApiPlatformParser::OUT_PREFIX , Dummy::class, ' get ' ),
266
328
]);
267
329
268
330
$ this ->assertEquals ([
0 commit comments