@@ -95,6 +95,38 @@ public function output_writes_resources_for_render_statements(): void
95
95
$ this ->assertEquals (['created ' => ['app/Http/Resources/UserCollection.php ' , 'app/Http/Resources/UserResource.php ' ]], $ this ->subject ->output ($ tree ));
96
96
}
97
97
98
+ #[Test]
99
+ public function output_writes_resource_for_resource_statements_whitout_generating_resource_collection_classes (): void
100
+ {
101
+ config (['blueprint.generate_resource_collection_classes ' => false ]);
102
+
103
+ $ template = $ this ->stub ('resource.stub ' );
104
+ $ this ->filesystem ->expects ('stub ' )
105
+ ->with ('resource.stub ' )
106
+ ->andReturn ($ template );
107
+
108
+ $ this ->filesystem ->shouldReceive ('exists ' )
109
+ ->with ('app/Http/Resources ' )
110
+ ->andReturns (false , true );
111
+ $ this ->filesystem ->expects ('makeDirectory ' )
112
+ ->with ('app/Http/Resources ' , 0755 , true );
113
+
114
+ $ this ->filesystem ->shouldReceive ('exists ' )
115
+ ->with ('app/Http/Resources/UserResource.php ' )
116
+ ->andReturns (false , true );
117
+ $ this ->filesystem ->expects ('put ' )
118
+ ->with ('app/Http/Resources/UserResource.php ' , $ this ->fixture ('resources/user.php ' ));
119
+
120
+ $ this ->filesystem ->shouldReceive ('put ' )
121
+ ->with ('app/Http/Resources/UserCollection.php ' )
122
+ ->never ();
123
+
124
+ $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('drafts/resource-statements.yaml ' ));
125
+ $ tree = $ this ->blueprint ->analyze ($ tokens );
126
+
127
+ $ this ->assertEquals (['created ' => ['app/Http/Resources/UserResource.php ' ]], $ this ->subject ->output ($ tree ));
128
+ }
129
+
98
130
#[Test]
99
131
public function output_writes_namespaced_classes (): void
100
132
{
@@ -164,6 +196,40 @@ public function output_writes_nested_resource(): void
164
196
], $ this ->subject ->output ($ tree ));
165
197
}
166
198
199
+ #[Test]
200
+ public function output_writes_nested_resource_without_generating_resource_collection_classes (): void
201
+ {
202
+ config (['blueprint.generate_resource_collection_classes ' => false ]);
203
+
204
+ $ this ->filesystem ->expects ('stub ' )
205
+ ->with ('resource.stub ' )
206
+ ->andReturn (file_get_contents ('stubs/resource.stub ' ));
207
+
208
+ $ this ->filesystem ->expects ('exists ' )
209
+ ->with ('app/Http/Resources/Api ' )
210
+ ->andReturns (false );
211
+ $ this ->filesystem ->expects ('makeDirectory ' )
212
+ ->with ('app/Http/Resources/Api ' , 0755 , true );
213
+
214
+ $ this ->filesystem ->expects ('exists ' )
215
+ ->times (4 )
216
+ ->with ('app/Http/Resources/Api/CertificateResource.php ' )
217
+ ->andReturns (false , true , true , true );
218
+ $ this ->filesystem ->expects ('put ' )
219
+ ->with ('app/Http/Resources/Api/CertificateResource.php ' , $ this ->fixture ('resources/certificate-with-nested-resource.php ' ));
220
+
221
+ $ this ->filesystem ->shouldReceive ('put ' )
222
+ ->with ('app/Http/Resources/Api/CertificateCollection.php ' )
223
+ ->never ();
224
+
225
+ $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('drafts/resource-nested.yaml ' ));
226
+ $ tree = $ this ->blueprint ->analyze ($ tokens );
227
+
228
+ $ this ->assertEquals ([
229
+ 'created ' => ['app/Http/Resources/Api/CertificateResource.php ' ],
230
+ ], $ this ->subject ->output ($ tree ));
231
+ }
232
+
167
233
#[Test]
168
234
public function output_api_resource_pagination (): void
169
235
{
@@ -198,4 +264,40 @@ public function output_api_resource_pagination(): void
198
264
'created ' => ['app/Http/Resources/PostCollection.php ' , 'app/Http/Resources/PostResource.php ' ],
199
265
], $ this ->subject ->output ($ tree ));
200
266
}
267
+
268
+ #[Test]
269
+ public function output_api_resource_pagination_without_generating_resource_collection_classes (): void
270
+ {
271
+ config (['blueprint.generate_resource_collection_classes ' => false ]);
272
+
273
+ $ this ->files ->expects ('stub ' )
274
+ ->with ('resource.stub ' )
275
+ ->andReturn (file_get_contents ('stubs/resource.stub ' ));
276
+
277
+ $ this ->files ->expects ('exists ' )
278
+ ->with ('app/Http/Resources ' )
279
+ ->andReturns (false , true );
280
+
281
+ $ this ->files ->expects ('makeDirectory ' )
282
+ ->with ('app/Http/Resources ' , 0755 , true );
283
+
284
+ $ this ->files ->expects ('exists ' )
285
+ ->times (4 )
286
+ ->with ('app/Http/Resources/PostResource.php ' )
287
+ ->andReturns (false , true , true , true );
288
+
289
+ $ this ->files ->expects ('put ' )
290
+ ->with ('app/Http/Resources/PostResource.php ' , $ this ->fixture ('resources/api-post-resource.php ' ));
291
+
292
+ $ this ->files ->expects ('put ' )
293
+ ->with ('app/Http/Resources/PostCollection.php ' )
294
+ ->never ();
295
+
296
+ $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('drafts/api-resource-pagination.yaml ' ));
297
+ $ tree = $ this ->blueprint ->analyze ($ tokens );
298
+
299
+ $ this ->assertEquals ([
300
+ 'created ' => ['app/Http/Resources/PostResource.php ' ],
301
+ ], $ this ->subject ->output ($ tree ));
302
+ }
201
303
}
0 commit comments