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

orchestral / canvas / 11829094503

14 Nov 2024 01:38AM UTC coverage: 91.499%. Remained the same
11829094503

Pull #40

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Pull Request #40: [7.] Add `#[\Override]`

592 of 647 relevant lines covered (91.5%)

29.05 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
/**
13
 * @see https://github.com/laravel/framework/blob/9.x/src/Illuminate/Foundation/Console/TestMakeCommand.php
14
 */
15
#[AsCommand(name: 'make:test', description: 'Create a new test class')]
16
class TestMakeCommand extends \Illuminate\Foundation\Console\TestMakeCommand
17
{
18
    use CodeGenerator;
19
    use UsesGeneratorOverrides;
20

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

30
        $this->addGeneratorPresetOptions();
18✔
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
        return $this->generateCode() ? self::SUCCESS : self::FAILURE;
18✔
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
    {
55
        $preset = $this->generatorPreset();
18✔
56

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

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

68
        return $this->replaceTestCase($stub, $testCase);
18✔
69
    }
70

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

78
        if (str_starts_with($testCase, '\\')) {
18✔
79
            $stub = str_replace('NamespacedDummyTestCase', trim($testCase, '\\'), $stub);
×
80
        } else {
81
            $stub = str_replace('NamespacedDummyTestCase', $namespaceTestCase, $stub);
18✔
82
        }
83

84
        $stub = str_replace(
18✔
85
            "use {$namespaceTestCase};\nuse {$namespaceTestCase};", "use {$namespaceTestCase};", $stub
18✔
86
        );
18✔
87

88
        $testCase = class_basename(trim($testCase, '\\'));
18✔
89

90
        return str_replace('DummyTestCase', $testCase, $stub);
18✔
91
    }
92

93
    /**
94
     * Resolve the fully-qualified path to the stub.
95
     *
96
     * @param  string  $stub
97
     * @return string
98
     */
99
    #[\Override]
100
    protected function resolveStubPath($stub)
101
    {
102
        $preset = $this->generatorPreset();
18✔
103

104
        if (! $preset instanceof GeneratorPreset) {
18✔
105
            return parent::resolveStubPath($stub);
×
106
        }
107

108
        return $preset->hasCustomStubPath() && file_exists($customPath = implode('/', [$preset->basePath(), trim($stub, '/')]))
18✔
109
            ? $customPath
×
110
            : $this->resolveDefaultStubPath($stub);
18✔
111
    }
112

113
    /**
114
     * Resolve the default fully-qualified path to the stub.
115
     *
116
     * @param  string  $stub
117
     * @return string
118
     */
119
    protected function resolveDefaultStubPath($stub)
120
    {
121
        return __DIR__.$stub;
18✔
122
    }
123

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

132
    /**
133
     * Get the destination class path.
134
     *
135
     * @param  string  $name
136
     * @return string
137
     */
138
    #[\Override]
139
    protected function getPath($name)
140
    {
141
        return $this->getPathUsingCanvas($name);
18✔
142
    }
143

144
    /**
145
     * Get the root namespace for the class.
146
     *
147
     * @return string
148
     */
149
    #[\Override]
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