Skip to content

Commit 1206ed2

Browse files
refactor: ModuleMakeCommandTest - remove unused modulePath variable and update path assertions for consistency
1 parent 75ad251 commit 1206ed2

3 files changed

+78
-27
lines changed

tests/Commands/Make/ModuleMakeCommandTest.php

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function test_it_generates_module_folders()
6161
foreach (config('modules.paths.generator') as $directory) {
6262
$this->assertDirectoryExists($this->module_path($directory['path']));
6363
}
64+
6465
$this->assertSame(0, $code);
6566
}
6667

@@ -72,6 +73,7 @@ public function test_it_generates_module_files()
7273
$path = $this->module_path($file);
7374
$this->assertTrue($this->finder->exists($path), "[$file] does not exists");
7475
}
76+
7577
$path = $this->module_path('module.json');
7678

7779
$this->assertTrue($this->finder->exists($path), '[module.json] does not exists');
@@ -189,46 +191,48 @@ public function test_it_generates_module_namespace_using_studly_case()
189191
{
190192
$code = $this->artisan('module:make', ['name' => ['ModuleName']]);
191193

192-
$file = $this->finder->get($this->module_path('app/Providers/ModuleNameServiceProvider.php', 'ModuleName'));
194+
$file = $this->finder->get($this->module_app_path('app/Providers/ModuleNameServiceProvider.php', 'ModuleName'));
193195

194196
$this->assertMatchesSnapshot($file);
195197
$this->assertSame(0, $code);
196198
}
197199

198200
public function test_it_generates_a_plain_module_with_no_resources()
199201
{
200-
$code = $this->artisan('module:make', ['name' => ['ModuleName'], '--plain' => true]);
202+
$code = $this->artisan('module:make', ['name' => ['Blog'], '--plain' => true]);
201203

202-
$path = $this->module_path('Providers/ModuleNameServiceProvider.php', 'ModuleName');
204+
$path = $this->module_app_path('app/Providers/BlogServiceProvider.php');
203205
$this->assertFalse($this->finder->exists($path));
204206

205-
$path = $this->module_path('Http/Controllers/ModuleNameController.php', 'ModuleName');
207+
$path = $this->module_app_path('app/Http/Controllers/BlogController.php');
206208
$this->assertFalse($this->finder->exists($path));
207209

208-
$path = $this->module_path('Database/Seeders/ModuleNameDatabaseSeeder.php', 'ModuleName');
210+
$path = $this->module_path('database/seeders/BlogDatabaseSeeder.php');
209211
$this->assertFalse($this->finder->exists($path));
210212

211213
$this->assertSame(0, $code);
212214
}
213215

214216
public function test_it_generates_a_plain_module_with_no_files()
215217
{
216-
$code = $this->artisan('module:make', ['name' => ['ModuleName'], '--plain' => true]);
218+
$code = $this->artisan('module:make', ['name' => ['Blog'], '--plain' => true]);
217219

218220
foreach (config('modules.stubs.files') as $file) {
219-
$path = $this->module_path($file, 'ModuleName');
221+
$path = $this->module_path($file);
220222
$this->assertFalse($this->finder->exists($path), "[$file] exists");
221223
}
222-
$path = $this->module_path('module.json', 'ModuleName');
224+
225+
$path = $this->module_path('module.json');
226+
223227
$this->assertTrue($this->finder->exists($path), '[module.json] does not exists');
224228
$this->assertSame(0, $code);
225229
}
226230

227231
public function test_it_generates_plain_module_with_no_service_provider_in_modulejson_file()
228232
{
229-
$code = $this->artisan('module:make', ['name' => ['ModuleName'], '--plain' => true]);
233+
$code = $this->artisan('module:make', ['name' => ['Blog'], '--plain' => true]);
230234

231-
$path = $this->module_path('module.json', 'ModuleName');
235+
$path = $this->module_path('module.json');
232236
$content = json_decode($this->finder->get($path));
233237

234238
$this->assertCount(0, $content->providers);
@@ -324,25 +328,28 @@ public function test_it_can_ignore_some_folders_to_generate_with_new_format()
324328

325329
public function test_it_can_ignore_resource_folders_to_generate()
326330
{
327-
$this->app['config']->set(
328-
'modules.paths.generator.seeder',
329-
['path' => 'Database/Seeders', 'generate' => false]
330-
);
331-
$this->app['config']->set('modules.paths.generator.provider', ['path' => 'Providers', 'generate' => false]);
332-
$this->app['config']->set(
333-
'modules.paths.generator.route-provider',
334-
['path' => 'Providers', 'generate' => false]
335-
);
336-
$this->app['config']->set(
337-
'modules.paths.generator.controller',
338-
['path' => 'Http/Controllers', 'generate' => false]
339-
);
331+
$this->app['config']->set('modules.paths.generator.seeder', [
332+
'path' => 'database/seeders',
333+
'generate' => false,
334+
]);
335+
$this->app['config']->set('modules.paths.generator.provider', [
336+
'path' => 'app/Providers',
337+
'generate' => false,
338+
]);
339+
$this->app['config']->set('modules.paths.generator.route-provider', [
340+
'path' => 'app/Providers',
341+
'generate' => false,
342+
]);
343+
$this->app['config']->set('modules.paths.generator.controller', [
344+
'path' => 'app/Http/Controllers',
345+
'generate' => false,
346+
]);
340347

341348
$code = $this->artisan('module:make', ['name' => ['Blog']]);
342349

343-
$this->assertFileDoesNotExist($this->module_path('Database/Seeders'));
344-
$this->assertFileDoesNotExist($this->module_path('Providers'));
345-
$this->assertFileDoesNotExist($this->module_path('Http/Controllers'));
350+
$this->assertFileDoesNotExist($this->module_path('database/seeders'));
351+
$this->assertFileDoesNotExist($this->module_app_path('app/Providers'));
352+
$this->assertFileDoesNotExist($this->module_app_path('app/Http/Controllers'));
346353
$this->assertSame(0, $code);
347354
}
348355

@@ -362,17 +369,20 @@ public function test_it_generates_disabled_module_with_disabled_flag()
362369
$this->assertSame(0, $code);
363370
}
364371

365-
public function test_it_generes_module_with_new_provider_location()
372+
public function test_it_generes_module_with_custom_provider_location()
366373
{
367374
$this->app['config']->set('modules.paths.generator.provider', ['path' => 'Base/Providers', 'generate' => true]);
368375

369376
$code = $this->artisan('module:make', ['name' => ['Blog']]);
370377

371378
$this->assertDirectoryExists($this->module_path('Base/Providers'));
379+
372380
$file = $this->finder->get($this->module_path('module.json'));
373381
$this->assertMatchesSnapshot($file);
382+
374383
$file = $this->finder->get($this->module_path('composer.json'));
375384
$this->assertMatchesSnapshot($file);
385+
376386
$this->assertSame(0, $code);
377387
}
378388

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "Blog",
3+
"alias": "blog",
4+
"description": "",
5+
"keywords": [],
6+
"priority": 0,
7+
"providers": [
8+
"Modules\\Blog\\Base\\Providers\\BlogServiceProvider"
9+
],
10+
"files": []
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "nwidart/blog",
3+
"description": "",
4+
"authors": [
5+
{
6+
"name": "Nicolas Widart",
7+
"email": "[email protected]"
8+
}
9+
],
10+
"extra": {
11+
"laravel": {
12+
"providers": [],
13+
"aliases": {
14+
15+
}
16+
}
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"Modules\\Blog\\App\\": "app/",
21+
"Modules\\Blog\\Database\\Factories\\": "database/factories/",
22+
"Modules\\Blog\\Database\\Seeders\\": "database/seeders/"
23+
}
24+
},
25+
"autoload-dev": {
26+
"psr-4": {
27+
"Modules\\Blog\\Tests\\": "tests/"
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)