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

orchestral / canvas / 22725820225

05 Mar 2026 03:46PM UTC coverage: 94.459%. Remained the same
22725820225

push

github

crynobone
Fix Laravel 13 compatibility

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

733 of 776 relevant lines covered (94.46%)

32.95 hits per line

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

91.67
/src/Console/ViewMakeCommand.php
1
<?php
2

3
namespace Orchestra\Canvas\Console;
4

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

12
use function Orchestra\Sidekick\Filesystem\join_paths;
13

14
#[AsCommand(name: 'make:view', description: 'Create a new view')]
15
class ViewMakeCommand extends \Illuminate\Foundation\Console\ViewMakeCommand
16
{
17
    use CodeGenerator;
18
    use TestGenerator {
19
        handleTestCreationUsingCanvas as protected handleTestCreationUsingCanvasFromTrait;
20
    }
21
    use UsesGeneratorOverrides;
22

23
    /**
24
     * Configures the current command.
25
     */
26
    #[\Override]
27
    protected function configure(): void
28
    {
29
        parent::configure();
2✔
30

31
        $this->addGeneratorPresetOptions();
2✔
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;
2✔
46
    }
47

48
    /**
49
     * Resolve the fully-qualified path to the stub.
50
     *
51
     * @param  string  $stub
52
     * @return string
53
     */
54
    #[\Override]
55
    protected function resolveStubPath($stub)
56
    {
57
        $preset = $this->generatorPreset();
2✔
58

59
        if (! $preset instanceof GeneratorPreset) {
2✔
60
            return parent::resolveStubPath($stub);
×
61
        }
62

63
        return $preset->hasCustomStubPath() && file_exists($customPath = join_paths($preset->basePath(), $stub))
2✔
64
            ? $customPath
×
65
            : $this->resolveDefaultStubPath($stub);
2✔
66
    }
67

68
    /**
69
     * Resolve the default fully-qualified path to the stub.
70
     *
71
     * @param  string  $stub
72
     * @return string
73
     */
74
    protected function resolveDefaultStubPath($stub)
75
    {
76
        return join_paths(__DIR__, $stub);
2✔
77
    }
78

79
    /**
80
     * Get the destination view path.
81
     *
82
     * @param  string  $name
83
     * @return string
84
     */
85
    #[\Override]
86
    protected function getPath($name)
87
    {
88
        /** @var string $extension */
89
        /** @phpstan-ignore argument.type */
90
        $extension = transform($this->option('extension'), fn (string $extension) => trim($extension));
2✔
91

92
        return $this->viewPath(
2✔
93
            $this->getNameInput().'.'.$extension,
2✔
94
        );
2✔
95
    }
96

97
    /**
98
     * Get the first view directory path from the application configuration.
99
     *
100
     * @param  string  $path
101
     * @return string
102
     */
103
    #[\Override]
104
    protected function viewPath($path = '')
105
    {
106
        return $this->viewPathUsingCanvas($path);
2✔
107
    }
108

109
    /**
110
     * Get the desired view name from the input.
111
     *
112
     * @return string
113
     */
114
    #[\Override]
115
    protected function getNameInput()
116
    {
117
        /** @phpstan-ignore argument.type, return.type */
118
        return transform($this->argument('name'), function (string $name) {
2✔
119
            return str_replace(['\\', '.'], '/', trim($name));
2✔
120
        });
2✔
121
    }
122

123
    /**
124
     * Create the matching test case if requested.
125
     *
126
     * @param  string  $path
127
     */
128
    protected function handleTestCreationUsingCanvas($path): bool
129
    {
130
        if (! $this->option('test') && ! $this->option('pest')) {
2✔
131
            return false;
1✔
132
        }
133

134
        $preset = $this->generatorPreset();
1✔
135

136
        if (! $preset instanceof GeneratorPreset) {
1✔
137
            return $this->handleTestCreationUsingCanvasFromTrait($path);
×
138
        }
139

140
        $namespaceTestCase = $testCase = $preset->canvas()->config(
1✔
141
            'testing.extends.feature',
1✔
142
            $preset->canvas()->is('laravel') ? 'Tests\TestCase' : 'Orchestra\Testbench\TestCase'
1✔
143
        );
1✔
144

145
        $stub = $this->files->get($this->getTestStub());
1✔
146

147
        if (Str::startsWith($testCase, '\\')) {
1✔
148
            $stub = str_replace('NamespacedDummyTestCase', trim($testCase, '\\'), $stub);
×
149
        } else {
150
            $stub = str_replace('NamespacedDummyTestCase', $namespaceTestCase, $stub);
1✔
151
        }
152

153
        $contents = str_replace(
1✔
154
            ['{{ namespace }}', '{{ class }}', '{{ name }}', 'DummyTestCase'],
1✔
155
            [$this->testNamespace(), $this->testClassName(), $this->testViewName(), class_basename(trim($testCase, '\\'))],
1✔
156
            $stub,
1✔
157
        );
1✔
158

159
        $this->files->ensureDirectoryExists(\dirname($this->getTestPath()), 0755, true);
1✔
160

161
        return $this->files->put($this->getTestPath(), $contents) !== false;
1✔
162
    }
163

164
    /**
165
     * Get the root namespace for the class.
166
     *
167
     * @return string
168
     */
169
    #[\Override]
170
    protected function rootNamespace()
171
    {
172
        return $this->rootNamespaceUsingCanvas();
2✔
173
    }
174

175
    /**
176
     * Get the destination test case path.
177
     *
178
     * @return string
179
     */
180
    #[\Override]
181
    protected function getTestPath()
182
    {
183
        $preset = $this->generatorPreset();
1✔
184

185
        $testPath = Str::of($this->testClassFullyQualifiedName())
1✔
186
            ->replace('\\', DIRECTORY_SEPARATOR)
1✔
187
            ->replaceFirst(join_paths('Tests', 'Feature'), join_paths(str_replace($preset->basePath(), '', $preset->testingPath()), 'Feature'))
1✔
188
            ->append('Test.php')
1✔
189
            ->value();
1✔
190

191
        return $preset->basePath().$testPath;
1✔
192
    }
193

194
    /**
195
     * Get the test stub file for the generator.
196
     *
197
     * @return string
198
     */
199
    #[\Override]
200
    protected function getTestStub()
201
    {
202
        $stubName = 'view.'.($this->option('pest') ? 'pest' : 'test').'.stub';
1✔
203

204
        return $this->resolveStubPath(join_paths('stubs', $stubName));
1✔
205
    }
206
}
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