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

orchestral / canvas / 6334368997

28 Sep 2023 04:02AM UTC coverage: 94.065% (+3.1%) from 90.922%
6334368997

Pull #24

github

crynobone
wip

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

16 of 16 new or added lines in 2 files covered. (100.0%)

317 of 337 relevant lines covered (94.07%)

30.81 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();
18✔
22

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

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

32
        return $this->replaceTestCase($stub, $testCase);
18✔
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);
18✔
41

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

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

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

54
        return str_replace('DummyTestCase', $testCase, $stub);
18✔
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();
18✔
66

67
        if ($preset instanceof GeneratorPreset) {
18✔
68
            return __DIR__.$stub;
18✔
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