1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Foundation\Generator\Commands; |
4
|
|
|
|
5
|
|
|
use Foundation\Exceptions\Exception; |
6
|
|
|
use Foundation\Generator\Abstracts\ClassGeneratorCommand; |
7
|
|
|
use Foundation\Generator\Events\TestGeneratedEvent; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
|
10
|
|
|
class TestMakeCommand extends ClassGeneratorCommand |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* The console command name. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $name = 'larapi:make:test'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'Create a new test class for the specified module.'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The name of the generated resource. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $generatorName = 'test'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The file path. |
35
|
|
|
* |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $filePath = '/Tests'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The event that will fire when the file is created. |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $event = TestGeneratedEvent::class; |
46
|
|
|
|
47
|
|
|
protected $types = [ |
48
|
|
|
"unit", |
49
|
|
|
"http", |
50
|
|
|
"service" |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
protected function stubOptions(): array |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
'NAMESPACE' => $this->getClassNamespace(), |
57
|
|
|
'CLASS' => $this->getClassName(), |
58
|
|
|
'TYPE' => $this->getType() |
59
|
|
|
]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function getType(): string |
63
|
|
|
{ |
64
|
|
|
return $this->getOption('type'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
protected function stubName(): string |
71
|
|
|
{ |
72
|
|
|
$type = $this->getType(); |
73
|
|
|
|
74
|
|
|
if (in_array($type, $this->types)) |
75
|
|
|
return "$type-test.stub"; |
76
|
|
|
|
77
|
|
|
throw new Exception("Test type not supported"); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get the console command options. |
82
|
|
|
* |
83
|
|
|
* @return array |
84
|
|
|
*/ |
85
|
|
|
protected function setOptions(): array |
86
|
|
|
{ |
87
|
|
|
return [ |
88
|
|
|
['type', $this->types, InputOption::VALUE_OPTIONAL, 'Indicates the type of the test.', $this->types[0]] |
89
|
|
|
]; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
protected function handleTypeOption($shortcut, $type, $question, $default) |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
return $this->anticipate('What is the type of the test?', $this->types, $default); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.