1 | <?php |
||
2 | |||
3 | namespace Salah3id\Domains\Commands; |
||
4 | |||
5 | use Illuminate\Support\Str; |
||
6 | use Salah3id\Domains\Support\Config\GenerateConfigReader; |
||
7 | use Salah3id\Domains\Support\Stub; |
||
8 | use Salah3id\Domains\Traits\DomainCommandTrait; |
||
9 | use Symfony\Component\Console\Input\InputArgument; |
||
10 | use Symfony\Component\Console\Input\InputOption; |
||
11 | |||
12 | class TestMakeCommand extends GeneratorCommand |
||
13 | { |
||
14 | use DomainCommandTrait; |
||
15 | |||
16 | protected $argumentName = 'name'; |
||
17 | protected $name = 'domain:make-test'; |
||
18 | protected $description = 'Create a new test class for the specified domain.'; |
||
19 | |||
20 | public function getDefaultNamespace(): string |
||
21 | { |
||
22 | $domain = $this->laravel['domains']; |
||
23 | |||
24 | if ($this->option('feature')) { |
||
25 | return $domain->config('paths.generator.test-feature.namespace') ?: $domain->config('paths.generator.test-feature.path', 'Tests/Feature'); |
||
26 | } |
||
27 | |||
28 | return $domain->config('paths.generator.test.namespace') ?: $domain->config('paths.generator.test.path', 'Tests/Unit'); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Get the console command arguments. |
||
33 | * |
||
34 | * @return array |
||
35 | */ |
||
36 | protected function getArguments() |
||
37 | { |
||
38 | return [ |
||
39 | ['name', InputArgument::REQUIRED, 'The name of the form request class.'], |
||
40 | ['domain', InputArgument::OPTIONAL, 'The name of domain will be used.'], |
||
41 | ]; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Get the console command options. |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | protected function getOptions() |
||
50 | { |
||
51 | return [ |
||
52 | ['feature', false, InputOption::VALUE_NONE, 'Create a feature test.'], |
||
53 | ]; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return mixed |
||
58 | */ |
||
59 | protected function getTemplateContents() |
||
60 | { |
||
61 | $domain = $this->laravel['domains']->findOrFail($this->getDomainName()); |
||
62 | $stub = '/unit-test.stub'; |
||
63 | |||
64 | if ($this->option('feature')) { |
||
65 | $stub = '/feature-test.stub'; |
||
66 | } |
||
67 | |||
68 | return (new Stub($stub, [ |
||
69 | 'NAMESPACE' => $this->getClassNamespace($domain), |
||
70 | 'CLASS' => $this->getClass(), |
||
71 | ]))->render(); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @return mixed |
||
76 | */ |
||
77 | protected function getDestinationFilePath() |
||
78 | { |
||
79 | $path = $this->laravel['domains']->getDomainPath($this->getDomainName()); |
||
80 | |||
81 | if ($this->option('feature')) { |
||
82 | $testPath = GenerateConfigReader::read('test-feature'); |
||
83 | } else { |
||
84 | $testPath = GenerateConfigReader::read('test'); |
||
85 | } |
||
86 | |||
87 | return $path . $testPath->getPath() . '/' . $this->getFileName() . '.php'; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @return string |
||
92 | */ |
||
93 | private function getFileName() |
||
94 | { |
||
95 | return Str::studly($this->argument('name')); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
96 | } |
||
97 | } |
||
98 |