Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 399 | Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Foundation\Console;
4
 
5
use Illuminate\Console\GeneratorCommand;
6
use Illuminate\Support\Str;
7
use Symfony\Component\Console\Attribute\AsCommand;
8
use Symfony\Component\Console\Input\InputOption;
9
 
10
#[AsCommand(name: 'make:test')]
11
class TestMakeCommand extends GeneratorCommand
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'make:test';
19
 
20
    /**
21
     * The name of the console command.
22
     *
23
     * This name is used to identify the command during lazy loading.
24
     *
25
     * @var string|null
26
     *
27
     * @deprecated
28
     */
29
    protected static $defaultName = 'make:test';
30
 
31
    /**
32
     * The console command description.
33
     *
34
     * @var string
35
     */
36
    protected $description = 'Create a new test class';
37
 
38
    /**
39
     * The type of class being generated.
40
     *
41
     * @var string
42
     */
43
    protected $type = 'Test';
44
 
45
    /**
46
     * Get the stub file for the generator.
47
     *
48
     * @return string
49
     */
50
    protected function getStub()
51
    {
52
        $suffix = $this->option('unit') ? '.unit.stub' : '.stub';
53
 
54
        return $this->option('pest')
55
            ? $this->resolveStubPath('/stubs/pest'.$suffix)
56
            : $this->resolveStubPath('/stubs/test'.$suffix);
57
    }
58
 
59
    /**
60
     * Resolve the fully-qualified path to the stub.
61
     *
62
     * @param  string  $stub
63
     * @return string
64
     */
65
    protected function resolveStubPath($stub)
66
    {
67
        return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
68
                        ? $customPath
69
                        : __DIR__.$stub;
70
    }
71
 
72
    /**
73
     * Get the destination class path.
74
     *
75
     * @param  string  $name
76
     * @return string
77
     */
78
    protected function getPath($name)
79
    {
80
        $name = Str::replaceFirst($this->rootNamespace(), '', $name);
81
 
82
        return base_path('tests').str_replace('\\', '/', $name).'.php';
83
    }
84
 
85
    /**
86
     * Get the default namespace for the class.
87
     *
88
     * @param  string  $rootNamespace
89
     * @return string
90
     */
91
    protected function getDefaultNamespace($rootNamespace)
92
    {
93
        if ($this->option('unit')) {
94
            return $rootNamespace.'\Unit';
95
        } else {
96
            return $rootNamespace.'\Feature';
97
        }
98
    }
99
 
100
    /**
101
     * Get the root namespace for the class.
102
     *
103
     * @return string
104
     */
105
    protected function rootNamespace()
106
    {
107
        return 'Tests';
108
    }
109
 
110
    /**
111
     * Get the console command options.
112
     *
113
     * @return array
114
     */
115
    protected function getOptions()
116
    {
117
        return [
118
            ['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the test already exists'],
119
            ['unit', 'u', InputOption::VALUE_NONE, 'Create a unit test'],
120
            ['pest', 'p', InputOption::VALUE_NONE, 'Create a Pest test'],
121
        ];
122
    }
123
}