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

orchestral / canvas / 4665386932

pending completion
4665386932

push

github

Mior Muhammad Zaki
wip

807 of 834 relevant lines covered (96.76%)

21.96 hits per line

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

95.65
/src/Processors/GeneratesTestingCode.php
1
<?php
2

3
namespace Orchestra\Canvas\Processors;
4

5
use Illuminate\Support\Str;
6
use Orchestra\Canvas\Core\GeneratesCode;
7
use Orchestra\Canvas\Core\Presets\Laravel;
8

9
/**
10
 * @property \Orchestra\Canvas\Commands\Testing $listener
11
 *
12
 * @see https://github.com/laravel/framework/blob/10.x/src/Illuminate/Foundation/Console/TestMakeCommand.php
13
 */
14
class GeneratesTestingCode extends GeneratesCode
15
{
16
    /**
17
     * Build the class with the given name.
18
     */
19
    protected function buildClass(string $name): string
20
    {
21
        $testCase = $this->options['unit']
13✔
22
            ? $this->preset->config('testing.extends.unit', 'PHPUnit\Framework\TestCase')
6✔
23
            : $this->preset->config(
7✔
24
                'testing.extends.feature',
7✔
25
                $this->preset instanceof Laravel ? 'Tests\TestCase' : 'Orchestra\Testbench\TestCase'
7✔
26
            );
7✔
27

28
        return $this->replaceTestCase(parent::buildClass($name), $testCase);
13✔
29
    }
30

31
    /**
32
     * Replace the model for the given stub.
33
     */
34
    protected function replaceTestCase(string $stub, string $testCase): string
35
    {
36
        $namespaceTestCase = $testCase = str_replace('/', '\\', $testCase);
13✔
37

38
        if (Str::startsWith($testCase, '\\')) {
13✔
39
            $stub = str_replace('NamespacedDummyTestCase', trim($testCase, '\\'), $stub);
×
40
        } else {
41
            $stub = str_replace('NamespacedDummyTestCase', $namespaceTestCase, $stub);
13✔
42
        }
43

44
        $stub = str_replace(
13✔
45
            "use {$namespaceTestCase};\nuse {$namespaceTestCase};", "use {$namespaceTestCase};", $stub
13✔
46
        );
13✔
47

48
        $testCase = class_basename(trim($testCase, '\\'));
13✔
49

50
        return str_replace('DummyTestCase', $testCase, $stub);
13✔
51
    }
52

53
    /**
54
     * Get the destination class path.
55
     */
56
    protected function getPath(string $name): string
57
    {
58
        $name = Str::replaceFirst($this->rootNamespace(), '', $name);
13✔
59

60
        return sprintf(
13✔
61
            '%s/tests/%s',
13✔
62
            $this->preset->basePath(),
13✔
63
            str_replace('\\', '/', $name).'.php'
13✔
64
        );
13✔
65
    }
66

67
    /**
68
     * Get the root namespace for the class.
69
     */
70
    protected function rootNamespace(): string
71
    {
72
        return $this->preset->config('testing.namespace', 'Tests');
13✔
73
    }
74
}
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