1111use Laravel \Nova \NovaServiceProvider ;
1212use RonasIT \Support \Tests \Support \Models \WelcomeBonus ;
1313use RonasIT \Support \Exceptions \EntityCreateException ;
14+ use RonasIT \Support \Tests \Support \Models \Post ;
1415
1516class NovaTestGeneratorTest extends TestCase
1617{
@@ -25,12 +26,15 @@ public function setUp(): void
2526
2627 public function testGenerateResourceNotExists ()
2728 {
28- $ this ->mockNovaServiceProviderExists ();
29-
3029 $ this ->mockClass (NovaTestGenerator::class, [
3130 $ this ->classExistsMethodCall (['models ' , 'News ' ]),
3231 ]);
3332
33+ $ this ->mockNativeGeneratorFunctions (
34+ $ this ->nativeClassExistsMethodCall ([NovaServiceProvider::class, true ]),
35+ $ this ->nativeClassExistsMethodCall (["App\Nova\NewsResource " ], false ),
36+ );
37+
3438 $ this ->assertExceptionThrew (
3539 className: ClassNotExistsException::class,
3640 message: 'Cannot create NovaNewsResourceTest cause NewsResource Nova resource does not exist. Create NewsResource Nova resource. ' ,
@@ -44,13 +48,16 @@ className: ClassNotExistsException::class,
4448
4549 public function testGenerateNovaTestAlreadyExists ()
4650 {
47- $ this ->mockNovaServiceProviderExists ();
48-
4951 $ this ->mockClass (NovaTestGenerator::class, [
5052 $ this ->classExistsMethodCall (['models ' , 'Post ' ]),
5153 $ this ->classExistsMethodCall (['nova ' , 'NovaPostResourceTest ' ]),
5254 ]);
5355
56+ $ this ->mockNativeGeneratorFunctions (
57+ $ this ->nativeClassExistsMethodCall ([NovaServiceProvider::class, true ]),
58+ $ this ->nativeClassExistsMethodCall (["App\Nova\Resources\PostResource " ]),
59+ );
60+
5461 $ this ->assertExceptionThrew (
5562 className: ClassAlreadyExistsException::class,
5663 message: "Cannot create NovaPostResourceTest cause it's already exist. Remove NovaPostResourceTest. " ,
@@ -71,6 +78,7 @@ public function testNovaTestStubNotExist()
7178
7279 $ this ->mockNativeGeneratorFunctions (
7380 $ this ->nativeClassExistsMethodCall ([NovaServiceProvider::class, true ]),
81+ $ this ->nativeClassExistsMethodCall (["App\Nova\WelcomeBonusResource " ]),
7482 $ this ->nativeClassExistsMethodCall ([WelcomeBonus::class, true ]),
7583 );
7684
@@ -105,8 +113,6 @@ className: WarningEvent::class,
105113
106114 public function testDumpStubNotExist ()
107115 {
108- $ this ->mockNovaServiceProviderExists ();
109-
110116 $ this ->mockNovaRequestClassCall ();
111117
112118 config ([
@@ -121,6 +127,11 @@ public function testDumpStubNotExist()
121127 $ this ->classExistsMethodCall (['factories ' , 'WelcomeBonusFactory ' ], false ),
122128 ]);
123129
130+ $ this ->mockNativeGeneratorFunctions (
131+ $ this ->nativeClassExistsMethodCall ([NovaServiceProvider::class, true ]),
132+ $ this ->nativeClassExistsMethodCall (["App\Nova\WelcomeBonusResource " ]),
133+ );
134+
124135 app (NovaTestGenerator::class)
125136 ->setModel ('WelcomeBonus ' )
126137 ->setMetaData (['resource_name ' => 'WelcomeBonusResource ' ])
@@ -156,6 +167,7 @@ public function testSuccess()
156167
157168 $ this ->mockNativeGeneratorFunctions (
158169 $ this ->nativeClassExistsMethodCall ([NovaServiceProvider::class, true ]),
170+ $ this ->nativeClassExistsMethodCall (["App\Nova\WelcomeBonusResource " ]),
159171 $ this ->nativeClassExistsMethodCall ([WelcomeBonus::class, true ]),
160172 );
161173
@@ -175,17 +187,21 @@ public function testSuccess()
175187
176188 public function testWithManySameResources ()
177189 {
178- $ this ->mockNativeGeneratorFunctions (
179- $ this ->nativeClassExistsMethodCall ([NovaServiceProvider::class, true ]),
180- );
190+ $ this ->mockNovaServiceProviderExists ();
191+
192+ $ this ->mockNovaRequestClassCall ();
193+
194+ $ this ->mockClass (NovaTestGenerator::class, [
195+ $ this ->classExistsMethodCall (['models ' , 'WelcomeBonus ' ]),
196+ ]);
181197
182198 $ this ->assertExceptionThrew (
183199 className: EntityCreateException::class,
184- message: 'Cannot create NovaPostResourceTest cause I am found a lot of suitable resources: Resources\PostResource Please, use --resource-name option ' ,
200+ message: 'Cannot create NovaWelcomeBonusResource Test cause was found a lot of suitable resources: WelcomeBonusResource, Resources\WelcomeBonus Please, use --resource-name option ' ,
185201 );
186202
187203 app (NovaTestGenerator::class)
188- ->setModel ('Post ' )
204+ ->setModel ('WelcomeBonus ' )
189205 ->setMetaData (['resource_name ' => null ])
190206 ->generate ();
191207 }
@@ -197,32 +213,33 @@ public function testSuccessWithoutSetMetaData()
197213 ]);
198214
199215 $ this ->mockClass (NovaTestGenerator::class, [
200- $ this ->classExistsMethodCall (['models ' , 'WelcomeBonus ' ]),
201- $ this ->classExistsMethodCall (['nova ' , 'NovaWelcomeBonusResourceTest ' ], false ),
216+ $ this ->classExistsMethodCall (['models ' , 'Post ' ]),
217+ $ this ->classExistsMethodCall (['nova ' , 'NovaPostResourceTest ' ], false ),
202218 $ this ->classExistsMethodCall (['models ' , 'User ' ], false ),
203- $ this ->classExistsMethodCall (['factories ' , 'WelcomeBonusFactory ' ], false ),
204- $ this ->classExistsMethodCall (['factories ' , 'WelcomeBonusFactory ' ], false ),
219+ $ this ->classExistsMethodCall (['factories ' , 'PostFactory ' ], false ),
220+ $ this ->classExistsMethodCall (['factories ' , 'PostFactory ' ], false ),
205221 ]);
206222
207223 $ this ->mockDBTransactionStartRollback ();
208224
209225 $ this ->mockNativeGeneratorFunctions (
210226 $ this ->nativeClassExistsMethodCall ([NovaServiceProvider::class, true ]),
211- $ this ->nativeClassExistsMethodCall ([WelcomeBonus::class, true ]),
227+ $ this ->nativeClassExistsMethodCall (["App\Nova\Resources\PostResource " ]),
228+ $ this ->nativeClassExistsMethodCall ([Post::class, true ]),
212229 );
213230
214231 $ this ->mockNovaRequestClassCall ();
215232
216233 app (NovaTestGenerator::class)
217- ->setModel ('WelcomeBonus ' )
234+ ->setModel ('Post ' )
218235 ->setMetaData (['resource_name ' => null ])
219236 ->generate ();
220237
221- $ this ->assertGeneratedFileEquals ('created_resource_test .php ' , 'tests/NovaWelcomeBonusResourceTest .php ' );
222- $ this ->assertGeneratedFileEquals ('dump .sql ' , 'tests/fixtures/NovaWelcomeBonusResourceTest/nova_welcome_bonus_dump .sql ' );
223- $ this ->assertGeneratedFileEquals ('create_welcome_bonus_request .json ' , 'tests/fixtures/NovaWelcomeBonusResourceTest/create_welcome_bonus_request .json ' );
224- $ this ->assertGeneratedFileEquals ('create_welcome_bonus_response .json ' , 'tests/fixtures/NovaWelcomeBonusResourceTest/create_welcome_bonus_response .json ' );
225- $ this ->assertGeneratedFileEquals ('update_welcome_bonus_request .json ' , 'tests/fixtures/NovaWelcomeBonusResourceTest/update_welcome_bonus_request .json ' );
238+ $ this ->assertGeneratedFileEquals ('created_post_resource_test .php ' , 'tests/NovaPostResourceTest .php ' );
239+ $ this ->assertGeneratedFileEquals ('post_dump .sql ' , 'tests/fixtures/NovaPostResourceTest/nova_post_dump .sql ' );
240+ $ this ->assertGeneratedFileEquals ('create_post_request .json ' , 'tests/fixtures/NovaPostResourceTest/create_post_request .json ' );
241+ $ this ->assertGeneratedFileEquals ('create_post_response .json ' , 'tests/fixtures/NovaPostResourceTest/create_post_response .json ' );
242+ $ this ->assertGeneratedFileEquals ('update_post_request .json ' , 'tests/fixtures/NovaPostResourceTest/update_post_request .json ' );
226243 }
227244
228245 public function testSuccessWithNestedFile (): void
@@ -243,6 +260,7 @@ public function testSuccessWithNestedFile(): void
243260
244261 $ this ->mockNativeGeneratorFunctions (
245262 $ this ->nativeClassExistsMethodCall ([NovaServiceProvider::class, true ]),
263+ $ this ->nativeClassExistsMethodCall (['App\Nova\Resources\WelcomeBonusDraftResource ' ]),
246264 $ this ->nativeClassExistsMethodCall ([WelcomeBonus::class, true ]),
247265 );
248266
@@ -266,7 +284,7 @@ public function testSetIncorrectModel(): void
266284
267285 $ this ->assertExceptionThrew (
268286 className: ClassNotExistsException::class,
269- message: "Cannot create NovaSomeUndefinedModelResourceTest cause SomeUndefinedModel does not exist. "
287+ message: "Cannot create NovaSomeUndefinedModelResource Test cause SomeUndefinedModel does not exist. "
270288 . "Create a SomeUndefinedModel Model by himself or run command 'php artisan make:entity SomeUndefinedModel --only-model'. " ,
271289 );
272290
0 commit comments