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

orchestral / canvas / 30921614659

04 Aug 2026 02:57PM UTC coverage: 91.944% (-2.5%) from 94.459%
30921614659

Pull #53

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Pull Request #53: Supports `laravel/doctor`

2 of 17 new or added lines in 2 files covered. (11.76%)

31 existing lines in 11 files now uncovered.

662 of 720 relevant lines covered (91.94%)

35.57 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
     * @return void
27
     */
28
    #[\Override]
29
    protected function configure()
30
    {
31
        parent::configure();
2✔
32

33
        $this->addGeneratorPresetOptions();
2✔
34
    }
35

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

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

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

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

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

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

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

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

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

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

136
        $preset = $this->generatorPreset();
1✔
137

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

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

147
        $stub = $this->files->get($this->getTestStub());
1✔
148

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

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

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

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

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

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

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

193
        return $preset->basePath().$testPath;
1✔
194
    }
195

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

206
        return $this->resolveStubPath(join_paths('stubs', $stubName));
1✔
207
    }
208
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc