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

orchestral / canvas / 9563332959

18 Jun 2024 10:23AM UTC coverage: 94.815%. Remained the same
9563332959

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 Illuminate\Support\Str;
7
use Orchestra\Canvas\Core\Concerns\CodeGenerator;
8
use Orchestra\Canvas\Core\Concerns\UsesGeneratorOverrides;
9
use Orchestra\Canvas\GeneratorPreset;
10
use Symfony\Component\Console\Attribute\AsCommand;
11

12
use function Illuminate\Filesystem\join_paths;
13

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

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

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

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

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

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

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

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

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

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

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

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

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

96
    /**
97
     * Resolve the fully-qualified path to the stub.
98
     *
99
     * @param  string  $stub
100
     * @return string
101
     */
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
    protected function getPath($name)
141
    {
142
        return $this->getPathUsingCanvas($name);
18✔
143
    }
144

145
    /**
146
     * Get the root namespace for the class.
147
     *
148
     * @return string
149
     */
150
    protected function rootNamespace()
151
    {
152
        return $this->generatorPreset()->testingNamespace();
18✔
153
    }
154
}
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