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

orchestral / canvas / 6047542927

01 Sep 2023 09:03AM UTC coverage: 94.11% (-0.2%) from 94.316%
6047542927

push

github

crynobone
Merge remote-tracking branch 'origin/master'

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

751 of 798 relevant lines covered (94.11%)

22.82 hits per line

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

95.83
/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
     * Handle generating code.
18
     */
19
    protected function generatingCode(string $stub, string $name): string
20
    {
21
        $stub = parent::generatingCode($stub, $name);
13✔
22

23
        $testCase = $this->options['unit']
13✔
24
            ? $this->preset->config('testing.extends.unit', 'PHPUnit\Framework\TestCase')
6✔
25
            : $this->preset->config(
7✔
26
                'testing.extends.feature',
7✔
27
                $this->preset instanceof Laravel ? 'Tests\TestCase' : 'Orchestra\Testbench\TestCase'
7✔
28
            );
7✔
29

30
        return $this->replaceTestCase($stub, $testCase);
13✔
31
    }
32

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

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

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

50
        $testCase = class_basename(trim($testCase, '\\'));
13✔
51

52
        return str_replace('DummyTestCase', $testCase, $stub);
13✔
53
    }
54

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

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

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