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

orchestral / canvas / 6185061391

14 Sep 2023 11:56AM UTC coverage: 85.128% (-4.8%) from 89.945%
6185061391

Pull #24

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Pull Request #24: Use Laravel Generator Preset

176 of 176 new or added lines in 11 files covered. (100.0%)

166 of 195 relevant lines covered (85.13%)

7.09 hits per line

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

90.91
/src/Console/TestMakeCommand.php
1
<?php
2

3
namespace Orchestra\Canvas\Console;
4

5
use Illuminate\Support\Str;
6
use Orchestra\Canvas\GeneratorPreset;
7
use Symfony\Component\Console\Attribute\AsCommand;
8

9
#[AsCommand(name: 'make:test', description: 'Create a new test class')]
10
class TestMakeCommand extends \Illuminate\Foundation\Console\TestMakeCommand
11
{
12
    /**
13
     * Replace the class name for the given stub.
14
     *
15
     * @param  string  $stub
16
     * @param  string  $name
17
     * @return string
18
     */
19
    protected function replaceClass($stub, $name)
20
    {
21
        $preset = $this->generatorPreset();
11✔
22

23
        $stub = parent::replaceClass($stub, $name);
11✔
24

25
        $testCase = $this->option('unit')
11✔
26
            ? $preset->canvas()->config('testing.extends.unit', 'PHPUnit\Framework\TestCase')
5✔
27
            : $preset->canvas()->config(
6✔
28
                'testing.extends.feature',
6✔
29
                $preset->canvas()->is('laravel') ? 'Tests\TestCase' : 'Orchestra\Testbench\TestCase'
6✔
30
            );
6✔
31

32
        return $this->replaceTestCase($stub, $testCase);
11✔
33
    }
34

35
    /**
36
     * Replace the model for the given stub.
37
     */
38
    protected function replaceTestCase(string $stub, string $testCase): string
39
    {
40
        $namespaceTestCase = $testCase = str_replace('/', '\\', $testCase);
11✔
41

42
        if (Str::startsWith($testCase, '\\')) {
11✔
43
            $stub = str_replace('NamespacedDummyTestCase', trim($testCase, '\\'), $stub);
×
44
        } else {
45
            $stub = str_replace('NamespacedDummyTestCase', $namespaceTestCase, $stub);
11✔
46
        }
47

48
        $stub = str_replace(
11✔
49
            "use {$namespaceTestCase};\nuse {$namespaceTestCase};", "use {$namespaceTestCase};", $stub
11✔
50
        );
11✔
51

52
        $testCase = class_basename(trim($testCase, '\\'));
11✔
53

54
        return str_replace('DummyTestCase', $testCase, $stub);
11✔
55
    }
56

57
    /**
58
     * Resolve the default fully-qualified path to the stub.
59
     *
60
     * @param  string  $stub
61
     * @return string
62
     */
63
    protected function resolveDefaultStubPath($stub)
64
    {
65
        $preset = $this->generatorPreset();
11✔
66

67
        if ($preset instanceof GeneratorPreset) {
11✔
68
            return __DIR__.$stub;
11✔
69
        }
70

71
        return parent::resolveDefaultStubPath($stub);
×
72
    }
73
}
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