@@ -52,6 +52,14 @@ class GenerateCrudTests extends Command
5252
5353 public function handle (): int
5454 {
55+ config (['database.default ' => 'sqlite ' ]);
56+ config (['database.connections.sqlite ' => [
57+ 'driver ' => 'sqlite ' ,
58+ 'database ' => ':memory: ' ,
59+ ]]);
60+
61+ $ this ->callSilent ('migrate ' );
62+
5563 $ controllers = collect ($ this ->discoverControllers ());
5664
5765 if ($ controllers ->isEmpty ()) {
@@ -61,8 +69,8 @@ public function handle(): int
6169 }
6270
6371 if ($ filter = $ this ->option ('controller ' )) {
64- // First try strict matching on the short name or full class name
65- $ exactMatches = $ controllers ->filter (function (array $ controller ) use ($ filter ) {
72+
73+ $ exactMatches = $ controllers ->filter (function (array $ controller ) use ($ filter ) {
6674 return $ controller ['short_name ' ] === $ filter || $ controller ['class ' ] === $ filter ;
6775 });
6876
@@ -193,12 +201,6 @@ protected function generateTestsForController(array $controllerInfo, ?string $op
193201 $ this ->line (" Generating {$ type } tests... " );
194202
195203 $ operations ->each (function (string $ operation ) use ($ controllerInfo , $ type ) {
196- if (! $ this ->operationEnabled ($ operation )) {
197- $ this ->line (" ⏭️ Skipping {$ operation } (disabled in configuration) " );
198-
199- return ;
200- }
201-
202204 $ this ->generateTestForOperation ($ controllerInfo , $ operation , $ type );
203205 });
204206 }
@@ -221,8 +223,8 @@ protected function generateTestForOperation(array $controllerInfo, string $opera
221223 }
222224
223225 // Check for stub override
224- $ stubName = "{$ type } - { $ operation }.stub " ;
225- $ operationStubPath = $ this ->getStubPath (' operations / ' .$ stubName );
226+ $ stubName = "{$ operation }.stub " ;
227+ $ operationStubPath = $ this ->getStubPath ($ type . ' / ' .$ stubName );
226228
227229 if (! File::exists ($ operationStubPath )) {
228230 $ this ->skippedOperations [$ controllerInfo ['short_name ' ]][] = "$ operation ( $ type) " ;
@@ -253,6 +255,15 @@ protected function generateTestForOperation(array $controllerInfo, string $opera
253255 );
254256 }
255257
258+ // Check for SoftDeletes
259+ if ($ model && class_exists ($ model ) && in_array ('Illuminate\Database\Eloquent\SoftDeletes ' , class_uses_recursive ($ model ))) {
260+ $ methods = str_replace ('__WITH_SOFT_DELETES_MISSING_ASSERTION__ ' , '$this->assertSoftDeleted($this->model, [$entry->getKeyName() => $entry->getKey()]); ' , $ methods );
261+ $ methods = str_replace ('__NON_SOFT_DELETE_MISSING_ASSERTION__ ' , '' , $ methods );
262+ } else {
263+ $ methods = str_replace ('__WITH_SOFT_DELETES_MISSING_ASSERTION__ ' , '' , $ methods );
264+ $ methods = str_replace ('__NON_SOFT_DELETE_MISSING_ASSERTION__ ' , '$this->assertDatabaseMissing($this->model, [$entry->getKeyName() => $entry->getKey()]); ' , $ methods );
265+ }
266+
256267 $ className = $ this ->resolveClassName ($ controllerInfo , $ operation );
257268
258269 $ controllerShortName = Str::replaceLast ('Controller ' , '' , $ controllerInfo ['short_name ' ]);
@@ -272,6 +283,7 @@ protected function generateTestForOperation(array $controllerInfo, string $opera
272283 $ routeSegment = $ this ->normalizeRoute ($ config ['route ' ] ?? '' );
273284
274285 $ testClass = $ this ->renderTestClass ([
286+ 'type ' => $ type ,
275287 'namespace ' => $ namespace ,
276288 'class ' => $ className ,
277289 'base_class ' => $ baseClassName ,
@@ -330,7 +342,7 @@ protected function ensureBaseTestClassExists(string $namespace, string $classNam
330342 return ;
331343 }
332344
333- $ stubName = $ type === ' feature ' ? ' feature-test-base.stub ' : ' browser-test- base.stub ' ;
345+ $ stubName = $ type. ' / base.stub ' ;
334346 $ stubPath = $ this ->getStubPath ($ stubName );
335347
336348 if (! File::exists ($ stubPath )) {
@@ -366,8 +378,8 @@ protected function ensureBaseTestClassExists(string $namespace, string $classNam
366378 */
367379 protected function renderTestClass (array $ data ): string
368380 {
369- $ type = $ this ->option ('type ' );
370- $ stubName = $ type === ' feature ' ? ' feature-test.stub ' : ' browser- test.stub ' ;
381+ $ type = $ data [ ' type ' ] ?? $ this ->option ('type ' ) ?? ' feature ' ;
382+ $ stubName = $ type. ' / test.stub ' ;
371383 $ stubPath = $ this ->getStubPath ($ stubName );
372384 $ stub = File::get ($ stubPath );
373385
@@ -606,8 +618,8 @@ protected function getStubPath(string $name): string
606618 $ framework = $ this ->option ('framework ' );
607619
608620 $ searchPaths = [
609- resource_path ('views/vendor/backpack/crud/stubs/crud- testing/ ' ),
610- __DIR__ .'/../../../resources/stubs/crud- testing/ ' ,
621+ resource_path ('views/vendor/backpack/crud/stubs/testing/ ' ),
622+ __DIR__ .'/../../../resources/stubs/testing/ ' ,
611623 ];
612624
613625 foreach ($ searchPaths as $ basePath ) {
@@ -631,7 +643,7 @@ protected function getStubPath(string $name): string
631643 }
632644 }
633645
634- return __DIR__ .'/../../../resources/stubs/crud- testing/ ' .$ name ;
646+ return __DIR__ .'/../../../resources/stubs/testing/ ' .$ name ;
635647 }
636648
637649 /**
0 commit comments