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

orchestral / canvas / 13362131109

17 Feb 2025 03:16AM UTC coverage: 90.954% (-3.5%) from 94.459%
13362131109

Pull #41

github

web-flow
Merge branch '9.x' into 9/dusk-test
Pull Request #41: [9.x] Laravel Dusk Integration

1 of 31 new or added lines in 2 files covered. (3.23%)

734 of 807 relevant lines covered (90.95%)

31.51 hits per line

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

0.0
/src/Console/DuskMakeCommand.php
1
<?php
2

3
namespace Orchestra\Canvas\Console;
4

5
use Laravel\Dusk\Console\MakeCommand;
6
use Orchestra\Canvas\Core\Concerns\CodeGenerator;
7
use Orchestra\Canvas\Core\Concerns\UsesGeneratorOverrides;
8
use Orchestra\Canvas\GeneratorPreset;
9

10
/**
11
 * @see https://github.com/laravel/framework/blob/11.x/src/Illuminate/Routing/Console/ControllerMakeCommand.php
12
 */
13
#[AsCommand(name: 'make:dusk', description: 'Create a new Dusk test class')]
14
class DuskMakeCommand extends MakeCommand
15
{
16
    use CodeGenerator;
17
    use UsesGeneratorOverrides;
18

19
    /**
20
     * Configures the current command.
21
     *
22
     * @return void
23
     */
24
    #[\Override]
25
    protected function configure()
26
    {
NEW
27
        parent::configure();
×
28

NEW
29
        $this->addGeneratorPresetOptions();
×
30
    }
31

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

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

NEW
57
        if (! $preset instanceof GeneratorPreset) {
×
NEW
58
            return $stub;
×
59
        }
60

NEW
61
        $testCase = $preset->canvas()->config(
×
NEW
62
            'testing.extends.browser',
×
NEW
63
            $preset->canvas()->is('laravel') ? 'Tests\DuskTestCase' : 'Orchestra\Testbench\Dusk\TestCase'
×
NEW
64
        );
×
65

NEW
66
        return $this->replaceTestCase($stub, $testCase);
×
67
    }
68

69
    /**
70
     * Replace the model for the given stub.
71
     */
72
    protected function replaceTestCase(string $stub, string $testCase): string
73
    {
NEW
74
        $namespaceTestCase = $testCase = str_replace('/', '\\', $testCase);
×
75

NEW
76
        if (Str::startsWith($testCase, '\\')) {
×
NEW
77
            $stub = str_replace('DummyNamespace', trim($testCase, '\\'), $stub);
×
78
        } else {
NEW
79
            $stub = str_replace('DummyNamespace', $namespaceTestCase, $stub);
×
80
        }
81

NEW
82
        $stub = str_replace(
×
NEW
83
            "use {$namespaceTestCase};\nuse {$namespaceTestCase};", "use {$namespaceTestCase};", $stub
×
NEW
84
        );
×
85

NEW
86
        $testCase = class_basename(trim($testCase, '\\'));
×
87

NEW
88
        return str_replace('DummyClass', $testCase, $stub);
×
89
    }
90

91
    /**
92
     * Resolve the fully-qualified path to the stub.
93
     *
94
     * @param  string  $stub
95
     * @return string
96
     */
97
    protected function resolveStubPath($stub)
98
    {
NEW
99
        $preset = $this->generatorPreset();
×
100

NEW
101
        if (! $preset instanceof GeneratorPreset) {
×
NEW
102
            return parent::resolveStubPath($stub);
×
103
        }
104

NEW
105
        return $preset->hasCustomStubPath() && file_exists($customPath = join_paths($preset->basePath(), $stub))
×
NEW
106
            ? $customPath
×
NEW
107
            : $this->resolveDefaultStubPath($stub);
×
108
    }
109

110
    /**
111
     * Resolve the default fully-qualified path to the stub.
112
     *
113
     * @param  string  $stub
114
     * @return string
115
     */
116
    protected function resolveDefaultStubPath($stub)
117
    {
NEW
118
        return join_paths(__DIR__, $stub);
×
119
    }
120

121
    /**
122
     * Get the generator preset source path.
123
     */
124
    protected function getGeneratorSourcePath(): string
125
    {
NEW
126
        return $this->generatorPreset()->testingPath();
×
127
    }
128

129
    /**
130
     * Get the destination class path.
131
     *
132
     * @param  string  $name
133
     * @return string
134
     */
135
    protected function getPath($name)
136
    {
NEW
137
        return $this->getPathUsingCanvas($name);
×
138
    }
139

140
    /**
141
     * Get the root namespace for the class.
142
     *
143
     * @return string
144
     */
145
    protected function rootNamespace()
146
    {
NEW
147
        return $this->generatorPreset()->testingNamespace().'Browser\\';
×
148
    }
149
}
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