1111
1212class NovaTestGenerator extends AbstractTestsGenerator
1313{
14+ protected $ novaModelName ;
15+
1416 public function generate (): void
1517 {
1618 if (class_exists (NovaServiceProvider::class)) {
17- if (!$ this ->classExists ( ' nova ' , $ this -> model )) {
19+ if (!$ this ->doesNovaResourceExists ( )) {
1820 $ this ->throwFailureException (
1921 ClassNotExistsException::class,
2022 "Cannot create Nova {$ this ->model }Test cause {$ this ->model } Nova resource does not exist. " ,
@@ -80,17 +82,17 @@ protected function getActions(): array
8082
8183 protected function loadNovaActions ()
8284 {
83- return app ("\\App \\Nova \\{$ this ->model }" )->actions (new NovaRequest ());
85+ return app ("\\App \\Nova \\{$ this ->novaModelName }" )->actions (new NovaRequest ());
8486 }
8587
8688 protected function loadNovaFields ()
8789 {
88- return app ("\\App \\Nova \\{$ this ->model }" )->fields (new NovaRequest ());
90+ return app ("\\App \\Nova \\{$ this ->novaModelName }" )->fields (new NovaRequest ());
8991 }
9092
9193 protected function loadNovaFilters ()
9294 {
93- return app ("\\App \\Nova \\{$ this ->model }" )->filters (new NovaRequest ());
95+ return app ("\\App \\Nova \\{$ this ->novaModelName }" )->filters (new NovaRequest ());
9496 }
9597
9698 public function getTestClassName (): string
@@ -103,7 +105,26 @@ protected function isFixtureNeeded($type): bool
103105 return true ;
104106 }
105107
106- protected function collectFilters ()
108+ protected function doesNovaResourceExists (): bool
109+ {
110+ $ possibleNovaModelNames = [
111+ "{$ this ->model }NovaResource " ,
112+ "{$ this ->model }Resource " ,
113+ $ this ->model
114+ ];
115+
116+ foreach ($ possibleNovaModelNames as $ modelName ) {
117+ if ($ this ->classExists ('nova ' , $ modelName )) {
118+ $ this ->novaModelName = $ modelName ;
119+
120+ return true ;
121+ }
122+ }
123+
124+ return false ;
125+ }
126+
127+ protected function collectFilters (): array
107128 {
108129 $ filtersFromFields = $ this ->getFiltersFromFields ();
109130 $ filters = $ this ->getFilters ();
0 commit comments