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

orchestral / canvas / 6224137920

18 Sep 2023 02:42PM UTC coverage: 90.984% (+1.0%) from 89.945%
6224137920

push

github

crynobone
wip

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

603 of 603 new or added lines in 34 files covered. (100.0%)

555 of 610 relevant lines covered (90.98%)

24.54 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 controller 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
    public function handle()
41
    {
42
        return $this->generateCode() ? self::SUCCESS : self::FAILURE;
18✔
43
    }
44

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

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

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

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

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

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

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

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

89
        return str_replace('DummyTestCase', $testCase, $stub);
18✔
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
    {
100
        $preset = $this->generatorPreset();
18✔
101

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

106
        return $preset->hasCustomStubPath() && file_exists($customPath = implode('/', [$preset->basePath(), trim($stub, '/')]))
18✔
107
            ? $customPath
×
108
            : $this->resolveDefaultStubPath($stub);
18✔
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
    {
119
        return __DIR__.$stub;
18✔
120
    }
121

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

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

141
    /**
142
     * Get the root namespace for the class.
143
     *
144
     * @return string
145
     */
146
    protected function rootNamespace()
147
    {
148
        return $this->generatorPreset()->testingNamespace();
18✔
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

© 2025 Coveralls, Inc