@@ -33,38 +33,53 @@ public function __construct()
3333 public function generate (): void
3434 {
3535 if (class_exists (NovaServiceProvider::class)) {
36- if (!$ this ->classExists ('models ' , $ this ->model )) {
36+ if (!$ this ->classExists ('models ' , $ this ->model , $ this -> modelSubFolder )) {
3737 $ this ->throwFailureException (
3838 ClassNotExistsException::class,
3939 "Cannot create Nova {$ this ->model }Resource Test cause {$ this ->model } does not exist. " ,
4040 "Create a {$ this ->model } Model by himself or run command 'php artisan make:entity {$ this ->model } --only-model'. "
4141 );
4242 }
4343
44- $ novaResources = $ this ->getCommonNovaResources ();
44+ if ( empty ( $ this ->novaResourceName )) {
4545
46- if (count ($ novaResources ) > 1 ){
47- $ foundedResources = implode (', ' , $ novaResources );
46+ $ novaResources = $ this ->getCommonNovaResources ();
4847
49- // TODO: pass $this->modelSubfolder to Exception after refactoring in https://github.com/RonasIT/laravel-entity-generator/issues/179
50- $ this ->throwFailureException (
51- EntityCreateException::class,
52- "Cannot create Nova {$ this ->model }ResourceTest cause was found a lot of suitable resources: {$ foundedResources }. " ,
53- 'Make test by yourself. '
54- );
48+ if (count ($ novaResources ) > 1 ) {
49+ $ foundedResources = implode (', ' , $ novaResources );
50+
51+ // TODO: pass $this->modelSubfolder to Exception after refactoring in https://github.com/RonasIT/laravel-entity-generator/issues/179
52+ $ this ->throwFailureException (
53+ EntityCreateException::class,
54+ "Cannot create Nova {$ this ->model }ResourceTest cause was found a lot of suitable resources: {$ foundedResources }. " ,
55+ 'Please, use --resource-name option. '
56+ );
57+ }
58+
59+ if (empty ($ novaResources )) {
60+ $ this ->throwFailureException (
61+ ClassNotExistsException::class,
62+ "Cannot create Nova {$ this ->model }ResourceTest cause {$ this ->model } Nova resource does not exist. " ,
63+ "Create {$ this ->model } Nova resource. "
64+ );
65+ }
66+
67+ $ this ->novaResourceName = array_pop ($ novaResources );
5568 }
5669
57- if (empty ($ novaResources )) {
70+ $ this ->shortNovaResourceName = Str::afterLast ($ this ->novaResourceName , '\\' );
71+
72+ $ this ->fullNovaResourcePath = "App \\Nova \\{$ this ->novaResourceName }" ;
73+
74+ if (!class_exists ($ this ->fullNovaResourcePath )) {
5875 $ this ->throwFailureException (
5976 ClassNotExistsException::class,
60- "Cannot create Nova {$ this ->model } ResourceTest cause {$ this ->model } Nova resource does not exist. " ,
61- "Create {$ this ->model } Nova resource. "
77+ "Cannot create Nova {$ this ->shortNovaResourceName } Test cause {$ this ->novaResourceName } Nova resource does not exist. " ,
78+ "Create {$ this ->novaResourceName } Nova resource. "
6279 );
6380 }
6481
65- $ this ->novaResourceName = array_pop ($ novaResources );
66-
67- if ($ this ->classExists ('nova ' , "Nova {$ this ->model }Test " )) {
82+ if ($ this ->classExists ('nova ' , "Nova {$ this ->shortNovaResourceName }Test " )) {
6883 $ this ->throwFailureException (
6984 ClassAlreadyExistsException::class,
7085 "Cannot create Nova {$ this ->model }ResourceTest cause it's already exist. " ,
@@ -94,25 +109,23 @@ public function generateTests(): void
94109 $ actions = $ this ->getActions ();
95110 $ filters = $ this ->collectFilters ();
96111
97- $ resourceClass = Str::afterLast ($ this ->novaResourceName , '\\' );
98-
99112 $ fileContent = $ this ->getStub ('nova_test ' , [
100113 'url_path ' => Str::kebab ($ this ->model ) . '-resources ' ,
101114 'entity_namespace ' => $ this ->getOrCreateNamespace ('models ' , $ this ->modelSubFolder ),
102115 'entity ' => $ this ->model ,
103- 'resource ' => $ resourceClass ,
116+ 'resource ' => $ this -> shortNovaResourceName ,
104117 'resource_path ' => "App \\Nova \\{$ this ->novaResourceName }" ,
105118 'entities ' => $ this ->getPluralName ($ this ->model ),
106- 'snake_resource ' => Str::snake ($ resourceClass ),
119+ 'snake_resource ' => Str::snake ($ this -> shortNovaResourceName ),
107120 'dromedary_entity ' => Str::lcfirst ($ this ->model ),
108121 'lower_entities ' => $ this ->getPluralName (Str::snake ($ this ->model )),
109122 'actions ' => $ actions ,
110123 'filters ' => $ filters ,
111124 ]);
112125
113- $ this ->saveClass ('tests ' , "Nova {$ resourceClass }Test " , $ fileContent );
126+ $ this ->saveClass ('tests ' , "Nova {$ this -> shortNovaResourceName }Test " , $ fileContent );
114127
115- event (new SuccessCreateMessage ("Created a new Nova test: Nova {$ resourceClass }Test " ));
128+ event (new SuccessCreateMessage ("Created a new Nova test: Nova {$ this -> shortNovaResourceName }Test " ));
116129 }
117130
118131 protected function getActions (): array
@@ -198,23 +211,6 @@ protected function isFixtureNeeded($type): bool
198211 return true ;
199212 }
200213
201- protected function getNovaResource (): string
202- {
203- $ commonResources = $ this ->getCommonNovaResources ();
204-
205- if (count ($ commonResources ) > 1 ) {
206- $ commonResources = implode (', ' , $ commonResources );
207-
208- $ this ->throwFailureException (
209- EntityCreateException::class,
210- "Cannot create Nova {$ this ->model }Resource Test cause was found a lot of suitable resources: $ commonResources " ,
211- "Please, use --resource-name option "
212- );
213- }
214-
215- return array_pop ($ commonResources );
216- }
217-
218214 protected function collectFilters (): array
219215 {
220216 $ filtersFromFields = $ this ->getFiltersFromFields ();
@@ -250,7 +246,7 @@ protected function getFiltersFromFields(): array
250246
251247 protected function getFilters (): array
252248 {
253- $ filters = [];
249+ $ filters = [];
254250 $ novaResourceFilters = $ this ->loadNovaFilters ();
255251
256252 foreach ($ novaResourceFilters as $ filter ) {
0 commit comments