1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelPlus\Extension\Generators\Commands; |
4
|
|
|
|
5
|
|
|
use Jumilla\Generators\Laravel\OneFileGeneratorCommand as BaseCommand; |
6
|
|
|
use Jumilla\Generators\FileGenerator; |
7
|
|
|
use LaravelPlus\Extension\Addons\Addon; |
8
|
|
|
use LaravelPlus\Extension\Generators\GeneratorCommandTrait; |
9
|
|
|
|
10
|
|
|
class TestMakeCommand extends BaseCommand |
11
|
|
|
{ |
12
|
|
|
use GeneratorCommandTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The console command singature. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $signature = 'make:test |
20
|
|
|
{name : The name of the class} |
21
|
|
|
{--a|addon= : The name of the addon} |
22
|
|
|
'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The console command description. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $description = '[+] Create a new test class'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The type of class being generated. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $type = 'Test'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The constructor. |
40
|
|
|
*/ |
41
|
5 |
|
public function __construct() |
42
|
|
|
{ |
43
|
5 |
|
parent::__construct(); |
44
|
|
|
|
45
|
5 |
|
$this->setStubDirectory(__DIR__.'/../stubs'); |
46
|
5 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get the directory path for root namespace. |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
2 |
|
protected function getRootDirectory() |
54
|
|
|
{ |
55
|
2 |
|
return $this->addon ? $this->addon->path('tests') : $this->laravel->basePath().'/tests'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get the root namespace for the class. |
60
|
|
|
* |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
2 |
|
protected function getRootNamespace() |
64
|
|
|
{ |
65
|
2 |
|
return ''; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the stub file for the generator. |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
2 |
|
protected function getStub() |
74
|
|
|
{ |
75
|
2 |
|
return 'test.stub'; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Generate file. |
80
|
|
|
* |
81
|
|
|
* @param \Jumilla\Generators\FileGenerator $generator |
82
|
|
|
* @param string $path |
83
|
|
|
* @param string $fqcn |
84
|
|
|
* |
85
|
|
|
* @return bool |
86
|
|
|
*/ |
87
|
2 |
|
protected function generateFile(FileGenerator $generator, $path, $fqcn) |
88
|
|
|
{ |
89
|
2 |
|
list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); |
90
|
|
|
|
91
|
2 |
|
return $generator->file($path)->template($this->getStub(), [ |
92
|
2 |
|
'namespace' => $namespace, |
93
|
2 |
|
'class' => $class, |
94
|
|
|
]); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|