Passed
Push — master ( c7459e...5c3821 )
by Arthur
22:05
created

TestMakeCommand::stubOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Foundation\Generator\Commands;
4
5
use Foundation\Exceptions\Exception;
6
use Foundation\Generator\Abstracts\AbstractGeneratorCommand;
7
use Symfony\Component\Console\Input\InputOption;
8
9
class TestMakeCommand extends AbstractGeneratorCommand
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'larapi:make:test';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Create a new test class for the specified module.';
24
25
    /**
26
     * The name of the generated resource.
27
     *
28
     * @var string
29
     */
30
    protected $generatorName = 'test';
31
32
    /**
33
     * The file path.
34
     *
35
     * @var string
36
     */
37
    protected $filePath = '/Tests';
38
39
    protected $types = [
40
        "unit",
41
        "http",
42
        "service"
43
    ];
44
45
    protected function stubOptions(): array
46
    {
47
        return [
48
            'NAMESPACE' => $this->getClassNamespace(),
49
            'CLASS' => $this->getClassName()
50
        ];
51
    }
52
53
    protected function getType(): string
54
    {
55
        return once(function () {
56
            $testType = $this->option('type') ?? $this->anticipate('What type of test would you like to create?', $this->types);
57
            if ($testType === null) {
58
                throw new Exception('type for test not specified');
59
            }
60
61
            return $testType;
62
        });
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    protected function stubName(): string
69
    {
70
        $type = $this->getType();
71
72
        if (in_array($type, $this->types))
73
            return "$type-test.stub";
74
75
        throw new Exception("Test type not supported");
76
    }
77
78
    /**
79
     * Get the console command options.
80
     *
81
     * @return array
82
     */
83
    protected function getOptions()
84
    {
85
        return [
86
            ['type', null, InputOption::VALUE_OPTIONAL, 'Indicates the type of the test.']
87
        ];
88
    }
89
}
90