@@ -209,8 +209,7 @@ protected function buildTestCases(Controller $controller): string
209
209
$ class = $ this ->buildFormRequestName ($ controller , $ name );
210
210
$ test_case = $ this ->buildFormRequestTestCase ($ controller ->fullyQualifiedClassName (), $ name , config ('blueprint.namespace ' ) . '\\Http \\Requests \\' . $ class ) . PHP_EOL . PHP_EOL . $ test_case ;
211
211
212
- $ this ->addImport ($ controller , 'JMac \\Testing \\Traits\AdditionalAssertions ' );
213
- $ this ->addTrait ($ controller , 'AdditionalAssertions ' );
212
+ $ this ->importAdditionalAssertionsToBaseTest ();
214
213
215
214
if ($ statement ->data ()) {
216
215
foreach ($ statement ->data () as $ data ) {
@@ -678,17 +677,35 @@ private function buildLines($lines): string
678
677
return str_pad (' ' , 4 ) . implode (PHP_EOL . str_pad (' ' , 4 ), $ lines );
679
678
}
680
679
681
- protected function buildTraits ( BlueprintModel $ model ): string
680
+ private function importAdditionalAssertionsToBaseTest ( ): void
682
681
{
683
- if (empty ($ this ->traits [$ model ->name ()])) {
684
- return '' ;
682
+ $ path = 'tests/TestCase.php ' ;
683
+ $ fullPath = base_path ($ path );
684
+
685
+ if (!$ this ->filesystem ->exists ($ fullPath )) {
686
+ return ;
685
687
}
686
688
687
- $ traits = collect ($ this ->traits [$ model ->name ()])
688
- ->unique ()
689
- ->sort ()
690
- ->implode ('::class)->use( ' );
689
+ $ content = $ this ->filesystem ->get ($ fullPath );
690
+
691
+ if (Str::contains ($ content , 'use JMac \\Testing \\Traits \\AdditionalAssertions; ' )) {
692
+ return ;
693
+ }
691
694
692
- return "pest()->use( {$ traits }::class); " ;
695
+ $ updatedContent = preg_replace (
696
+ [
697
+ '/as BaseTestCase;/ ' ,
698
+ '/abstract class TestCase extends BaseTestCase\s*{/ ' ,
699
+ ],
700
+ [
701
+ 'as BaseTestCase; ' . PHP_EOL . 'use JMac \\Testing \\Traits \\AdditionalAssertions; ' ,
702
+ 'abstract class TestCase extends BaseTestCase ' . PHP_EOL . '{ ' . PHP_EOL . ' use AdditionalAssertions; ' ,
703
+ ],
704
+ $ content
705
+ );
706
+
707
+ $ this ->output ['updated ' ][] = $ path ;
708
+
709
+ $ this ->filesystem ->put ($ fullPath , $ updatedContent );
693
710
}
694
711
}
0 commit comments