• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

orchestral / canvas / 11950406233

21 Nov 2024 09:32AM UTC coverage: 94.815%. Remained the same
11950406233

push

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

640 of 675 relevant lines covered (94.81%)

24.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/Console/TestMakeCommand.php
1
<?php
2

3
namespace Orchestra\Canvas\Console;
4

5
use Illuminate\Filesystem\Filesystem;
6
use Orchestra\Canvas\Core\Concerns\CodeGenerator;
7
use Orchestra\Canvas\Core\Concerns\UsesGeneratorOverrides;
8
use Orchestra\Canvas\GeneratorPreset;
9
use Symfony\Component\Console\Attribute\AsCommand;
10

11
use function Illuminate\Filesystem\join_paths;
12

13
/**
14
 * @see https://github.com/laravel/framework/blob/10.x/src/Illuminate/Foundation/Console/TestMakeCommand.php
15
 */
16
#[AsCommand(name: 'make:test', description: 'Create a new test class')]
17
class TestMakeCommand extends \Illuminate\Foundation\Console\TestMakeCommand
18
{
19
    use CodeGenerator;
20
    use UsesGeneratorOverrides;
21

22
    /**
23
     * Create a new creator command instance.
24
     *
25
     * @return void
26
     */
27
    public function __construct(Filesystem $files)
28
    {
29
        parent::__construct($files);
18✔
30

31
        $this->addGeneratorPresetOptions();
18✔
32
    }
33

34
    /**
35
     * Execute the console command.
36
     *
37
     * @return bool|null
38
     *
39
     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
40
     */
41
    #[\Override]
42
    public function handle()
43
    {
44
        /** @phpstan-ignore return.type */
45
        return $this->generateCode() ? self::SUCCESS : self::FAILURE;
18✔
46
    }
47

48
    /**
49
     * Replace the class name for the given stub.
50
     *
51
     * @param  string  $stub
52
     * @param  string  $name
53
     * @return string
54
     */
55
    protected function generatingCode($stub, $name)
56
    {
57
        $preset = $this->generatorPreset();
18✔
58

59
        if (! $preset instanceof GeneratorPreset) {
18✔
60
            return $stub;
×
61
        }
62

63
        $testCase = $this->option('unit')
18✔
64
            ? $preset->canvas()->config('testing.extends.unit', 'PHPUnit\Framework\TestCase')
5✔
65
            : $preset->canvas()->config(
13✔
66
                'testing.extends.feature',
13✔
67
                $preset->canvas()->is('laravel') ? 'Tests\TestCase' : 'Orchestra\Testbench\TestCase'
13✔
68
            );
13✔
69

70
        return $this->replaceTestCase($stub, $testCase);
18✔
71
    }
72

73
    /**
74
     * Replace the model for the given stub.
75
     */
76
    protected function replaceTestCase(string $stub, string $testCase): string
77
    {
78
        $namespaceTestCase = $testCase = str_replace('/', '\\', $testCase);
18✔
79

80
        if (str_starts_with($testCase, '\\')) {
18✔
81
            $stub = str_replace('NamespacedDummyTestCase', trim($testCase, '\\'), $stub);
×
82
        } else {
83
            $stub = str_replace('NamespacedDummyTestCase', $namespaceTestCase, $stub);
18✔
84
        }
85

86
        $stub = str_replace(
18✔
87
            "use {$namespaceTestCase};\nuse {$namespaceTestCase};", "use {$namespaceTestCase};", $stub
18✔
88
        );
18✔
89

90
        $testCase = class_basename(trim($testCase, '\\'));
18✔
91

92
        return str_replace('DummyTestCase', $testCase, $stub);
18✔
93
    }
94

95
    /**
96
     * Resolve the fully-qualified path to the stub.
97
     *
98
     * @param  string  $stub
99
     * @return string
100
     */
101
    #[\Override]
102
    protected function resolveStubPath($stub)
103
    {
104
        $preset = $this->generatorPreset();
18✔
105

106
        if (! $preset instanceof GeneratorPreset) {
18✔
107
            return parent::resolveStubPath($stub);
×
108
        }
109

110
        return $preset->hasCustomStubPath() && file_exists($customPath = join_paths($preset->basePath(), $stub))
18✔
111
            ? $customPath
×
112
            : $this->resolveDefaultStubPath($stub);
18✔
113
    }
114

115
    /**
116
     * Resolve the default fully-qualified path to the stub.
117
     *
118
     * @param  string  $stub
119
     * @return string
120
     */
121
    protected function resolveDefaultStubPath($stub)
122
    {
123
        return join_paths(__DIR__, $stub);
18✔
124
    }
125

126
    /**
127
     * Get the generator preset source path.
128
     */
129
    protected function getGeneratorSourcePath(): string
130
    {
131
        return $this->generatorPreset()->testingPath();
18✔
132
    }
133

134
    /**
135
     * Get the destination class path.
136
     *
137
     * @param  string  $name
138
     * @return string
139
     */
140
    #[\Override]
141
    protected function getPath($name)
142
    {
143
        return $this->getPathUsingCanvas($name);
18✔
144
    }
145

146
    /**
147
     * Get the root namespace for the class.
148
     *
149
     * @return string
150
     */
151
    #[\Override]
152
    protected function rootNamespace()
153
    {
154
        return $this->generatorPreset()->testingNamespace();
18✔
155
    }
156
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc