|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rawilk\LaravelModules\Commands\Generators; |
|
4
|
|
|
|
|
5
|
|
|
use Rawilk\LaravelModules\Support\Config\GenerateConfigReader; |
|
6
|
|
|
use Rawilk\LaravelModules\Support\Stub; |
|
7
|
|
|
use Rawilk\LaravelModules\Traits\ModuleCommands; |
|
8
|
|
|
|
|
9
|
|
|
class TestMakeCommand extends GeneratorCommand |
|
10
|
|
|
{ |
|
11
|
|
|
use ModuleCommands; |
|
12
|
|
|
|
|
13
|
|
|
/** @var string */ |
|
14
|
|
|
protected $argumentName = 'name'; |
|
15
|
|
|
|
|
16
|
|
|
/** @var string */ |
|
17
|
|
|
protected $signature = 'module:make-test |
|
18
|
|
|
{name : The name of the test} |
|
19
|
|
|
{module? : The name of the module to create the test for} |
|
20
|
|
|
{--feature : Indicates the test is a feature test}'; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
protected $description = 'Create a new test class for the specified module.'; |
|
24
|
|
|
|
|
25
|
|
|
protected function getDefaultNamespace(): string |
|
26
|
|
|
{ |
|
27
|
|
|
/** @var \Rawilk\LaravelModules\Contracts\Repository $module */ |
|
28
|
|
|
$module = $this->laravel['modules']; |
|
29
|
|
|
|
|
30
|
|
|
if ($this->option('feature')) { |
|
31
|
|
|
return $module->config('paths.generator.test-feature.namespace') ?: $module->config('paths.generator.test-feature.path', 'tests/Feature'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
return $module->config('paths.generator.test.namespace') ?: $module->config('paths.generator.test.path', 'tests/Unit'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function getDestinationFilePath(): string |
|
38
|
|
|
{ |
|
39
|
|
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
|
40
|
|
|
|
|
41
|
|
|
if ($this->option('feature')) { |
|
42
|
|
|
$testPath = GenerateConfigReader::read('test-feature'); |
|
43
|
|
|
} else { |
|
44
|
|
|
$testPath = GenerateConfigReader::read('test'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $path . $testPath->getPath() . '/' . $this->getFileName() . '.php'; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
protected function getTemplateContents(): string |
|
51
|
|
|
{ |
|
52
|
|
|
/** @var \Rawilk\LaravelModules\Module $module */ |
|
53
|
|
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
|
54
|
|
|
|
|
55
|
|
|
return (new Stub($this->getStubName(), [ |
|
56
|
|
|
'NAMESPACE' => $this->getClassNamespace($module), |
|
57
|
|
|
'CLASS' => $this->getClass(), |
|
58
|
|
|
]))->render(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
private function getStubName(): string |
|
62
|
|
|
{ |
|
63
|
|
|
if ($this->option('feature')) { |
|
64
|
|
|
return '/feature-test.stub'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return '/unit-test.stub'; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|