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

orchestral / canvas / 13362212337

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

Pull #41

github

web-flow
Update DuskMakeCommand.php
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
use Symfony\Component\Console\Attribute\AsCommand;
10

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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