12
12
use Blueprint \Models \Statements \QueryStatement ;
13
13
use Blueprint \Models \Statements \RedirectStatement ;
14
14
use Blueprint \Models \Statements \RenderStatement ;
15
+ use Blueprint \Models \Statements \RespondStatement ;
15
16
use Blueprint \Models \Statements \SendStatement ;
16
17
use Blueprint \Models \Statements \SessionStatement ;
17
18
use Blueprint \Models \Statements \ValidateStatement ;
@@ -23,6 +24,7 @@ class TestGenerator implements Generator
23
24
const TESTS_REDIRECT = 2 ;
24
25
const TESTS_SAVE = 4 ;
25
26
const TESTS_DELETE = 8 ;
27
+ const TESTS_RESPONDS = 16 ;
26
28
27
29
/** @var \Illuminate\Contracts\Filesystem\Filesystem */
28
30
private $ files ;
@@ -289,6 +291,20 @@ protected function buildTestCases(Controller $controller)
289
291
$ assertion .= ')); ' ;
290
292
291
293
array_unshift ($ assertions ['response ' ], $ assertion );
294
+ } elseif ($ statement instanceof RespondStatement) {
295
+ $ tested_bits |= self ::TESTS_RESPONDS ;
296
+
297
+ if ($ statement ->content ()) {
298
+ array_unshift ($ assertions ['response ' ], '$response->assertJson($ ' . $ statement ->content () . '); ' );
299
+ }
300
+
301
+ if ($ statement ->status () === 200 ) {
302
+ array_unshift ($ assertions ['response ' ], '$response->assertOk(); ' );
303
+ } elseif ($ statement ->status () === 204 ) {
304
+ array_unshift ($ assertions ['response ' ], '$response->assertNoContent(); ' );
305
+ } else {
306
+ array_unshift ($ assertions ['response ' ], '$response->assertNoContent( ' . $ statement ->status () . '); ' );
307
+ }
292
308
} elseif ($ statement instanceof SessionStatement) {
293
309
$ assertions ['response ' ][] = sprintf ('$response->assertSessionHas( \'%s \', %s); ' , $ statement ->reference (), '$ ' . str_replace ('. ' , '-> ' , $ statement ->reference ()));
294
310
} elseif ($ statement instanceof EloquentStatement) {
@@ -491,6 +507,10 @@ private function buildTestCaseName(string $name, int $tested_bits)
491
507
$ verifications [] = 'redirects ' ;
492
508
}
493
509
510
+ if ($ tested_bits & self ::TESTS_RESPONDS ) {
511
+ $ verifications [] = 'responds_with ' ;
512
+ }
513
+
494
514
if (empty ($ verifications )) {
495
515
return $ name . '_behaves_as_expected ' ;
496
516
}
0 commit comments