TestMakeCommand   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 99
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getRootDirectory() 0 4 2
A getRootNamespace() 0 4 2
A getDefaultNamespace() 0 4 2
A getStub() 0 4 2
A generateFile() 0 10 1
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
        {--u|unit : Create a unit test}
23
    ';
24
25
    /**
26
     * The console command description.
27
     *
28
     * @var string
29
     */
30
    protected $description = '[+] Create a new test class';
31
32
    /**
33
     * The type of class being generated.
34
     *
35
     * @var string
36
     */
37
    protected $type = 'Test';
38
39
    /**
40
     * The constructor.
41
     */
42 7
    public function __construct()
43
    {
44 7
        parent::__construct();
45
46 7
        $this->setStubDirectory(__DIR__.'/../stubs');
47 7
    }
48
49
    /**
50
     * Get the directory path for root namespace.
51
     *
52
     * @return string
53
     */
54 4
    protected function getRootDirectory()
55
    {
56 4
        return $this->addon ? $this->addon->path('tests') : $this->laravel->basePath().'/tests';
57
    }
58
59
    /**
60
     * Get the default namespace for the class.
61
     *
62
     * @return $string
63
     */
64 4
     protected function getRootNamespace()
65
     {
66 4
         return $this->addon ? 'Tests\\'.studly_case($this->addon->name()) : 'Tests';
67
     }
68
 
69
     /**
70
     * Get the root namespace for the class.
71
     *
72
     * @return string
73
     */
74 4
    protected function getDefaultNamespace()
75
    {
76 4
        return $this->getRootNamespace() . ($this->option('unit') ? '\\Unit' : '\\Feature');
77
    }
78
79
    /**
80
     * Get the stub file for the generator.
81
     *
82
     * @return string
83
     */
84 4
    protected function getStub()
85
    {
86 4
        return $this->option('unit') ? 'test-unit.stub' : 'test-feature.stub';
87
    }
88
89
    /**
90
     * Generate file.
91
     *
92
     * @param \Jumilla\Generators\FileGenerator $generator
93
     * @param string $path
94
     * @param string $fqcn
95
     *
96
     * @return bool
97
     */
98 4
    protected function generateFile(FileGenerator $generator, $path, $fqcn)
99
    {
100 4
        list($namespace, $class) = $this->splitFullQualifyClassName($fqcn);
101
102 4
        return $generator->file($path)->template($this->getStub(), [
103 4
            'namespace' => $namespace,
104 4
            'root_namespace' => $this->getRootNamespace(),
105 4
            'class' => $class,
106
        ]);
107
    }
108
}
109