@@ -21,13 +21,6 @@ class NovaTestGenerator extends AbstractTestsGenerator
2121 public function generate (): void
2222 {
2323 if (class_exists (NovaServiceProvider::class)) {
24- if ($ this ->classExists ('nova ' , "Nova {$ this ->model }ResourceTest " )) {
25-
26- $ path = $ this ->getClassPath ('nova ' , "Nova {$ this ->model }ResourceTest " );
27-
28- throw new ResourceAlreadyExistsException ($ path );
29- }
30-
3124 $ novaResources = $ this ->getCommonNovaResources ();
3225
3326 if (count ($ novaResources ) > 1 ) {
@@ -51,7 +44,11 @@ public function generate(): void
5144
5245 $ this ->novaResourceClassName = Arr::first ($ novaResources );
5346
54- $ this ->entity = Str::afterLast ($ this ->novaResourceClassName , '\\' );
47+ if ($ this ->classExists ('nova ' , "Nova {$ this ->getTestingEntityName ()}Test " )) {
48+ $ path = $ this ->getClassPath ('nova ' , "Nova {$ this ->getTestingEntityName ()}Test " );
49+
50+ throw new ResourceAlreadyExistsException ($ path );
51+ }
5552
5653 parent ::generate ();
5754 } else {
@@ -71,19 +68,19 @@ public function generateTests(): void
7168 $ fileContent = $ this ->getStub ('nova_test ' , [
7269 'entity_namespace ' => $ this ->getNamespace ('models ' , $ this ->modelSubFolder ),
7370 'entity ' => $ this ->model ,
74- 'resource_name ' => $ this ->entity ,
71+ 'resource_name ' => $ this ->getTestingEntityName () ,
7572 'resource_namespace ' => $ this ->novaResourceClassName ,
76- 'snake_resource ' => Str::snake ($ this ->entity ),
73+ 'snake_resource ' => Str::snake ($ this ->getTestingEntityName () ),
7774 'dromedary_entity ' => Str::lcfirst ($ this ->model ),
7875 'lower_entities ' => $ this ->getPluralName (Str::snake ($ this ->model )),
7976 'actions ' => $ actions ,
8077 'filters ' => $ filters ,
8178 'models_namespace ' => $ this ->getNamespace ('models ' ),
8279 ]);
8380
84- $ this ->saveClass ('tests ' , " Nova { $ this ->model } ResourceTest " , $ fileContent );
81+ $ this ->saveClass ('tests ' , $ this ->getTestClassName () , $ fileContent );
8582
86- event (new SuccessCreateMessage ("Created a new Nova test: Nova {$ this ->model } ResourceTest " ));
83+ event (new SuccessCreateMessage ("Created a new Nova test: {$ this ->getTestClassName ()} " ));
8784 }
8885
8986 protected function getActions (): array
@@ -161,7 +158,7 @@ protected function loadNovaFilters()
161158
162159 public function getTestClassName (): string
163160 {
164- return "Nova {$ this ->entity }Test " ;
161+ return "Nova {$ this ->getTestingEntityName () }Test " ;
165162 }
166163
167164 protected function isFixtureNeeded ($ type ): bool
@@ -219,8 +216,13 @@ protected function getFilters(): array
219216
220217 protected function getDumpName (): string
221218 {
222- $ entityName = Str::snake ($ this ->entity );
219+ $ entityName = Str::snake ($ this ->getTestingEntityName () );
223220
224221 return "nova_ {$ entityName }_dump.sql " ;
225222 }
223+
224+ protected function getTestingEntityName (): string
225+ {
226+ return Str::afterLast ($ this ->novaResourceClassName , '\\' );
227+ }
226228}
0 commit comments