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

orchestral / workbench / 11473999849

23 Oct 2024 06:03AM UTC coverage: 90.857% (-0.5%) from 91.379%
11473999849

push

github

crynobone
wip

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

0 of 2 new or added lines in 1 file covered. (0.0%)

159 of 175 relevant lines covered (90.86%)

7.14 hits per line

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

93.33
/src/Workbench.php
1
<?php
2

3
namespace Orchestra\Workbench;
4

5
use Illuminate\Support\Arr;
6

7
use function Orchestra\Testbench\join_paths;
8
use function Orchestra\Testbench\package_path;
9
use function Orchestra\Testbench\workbench;
10
use function Orchestra\Testbench\workbench_path;
11

12
/**
13
 * @phpstan-import-type TWorkbenchConfig from \Orchestra\Testbench\Foundation\Config
14
 *
15
 * @phpstan-type TStubFiles array{
16
 *   config: ?string,
17
 *   'config.basic': ?string,
18
 *   gitignore: ?string,
19
 *   'routes.api': ?string,
20
 *   'routes.console': ?string,
21
 *   'routes.web': ?string,
22
 *   'seeders.database': ?string
23
 * }
24
 */
25
class Workbench
26
{
27
    /**
28
     * Files of stub files overrides.
29
     *
30
     * @var array<string, ?string>
31
     *
32
     * @phpstan-var TStubFiles
33
     */
34
    protected static array $files = [
35
        'config' => null,
36
        'config.basic' => null,
37
        'gitignore' => null,
38
        'routes.api' => null,
39
        'routes.console' => null,
40
        'routes.web' => null,
41
        'seeders.database' => null,
42
    ];
43

44
    /**
45
     * Get the path to the laravel folder.
46
     */
47
    public static function laravelPath(array|string $path = ''): string
48
    {
49
        return app()->basePath(
1✔
50
            join_paths(...Arr::wrap(\func_num_args() > 1 ? \func_get_args() : $path))
1✔
51
        );
1✔
52
    }
53

54
    /**
55
     * Get the path to the package folder.
56
     */
57
    public static function packagePath(array|string $path = ''): string
58
    {
59
        return package_path(
1✔
60
            ...Arr::wrap(\func_num_args() > 1 ? \func_get_args() : $path)
1✔
61
        );
1✔
62
    }
63

64
    /**
65
     * Get the path to the workbench folder.
66
     */
67
    public static function path(array|string $path = ''): string
68
    {
69
        return workbench_path(
2✔
70
            ...Arr::wrap(\func_num_args() > 1 ? \func_get_args() : $path)
2✔
71
        );
2✔
72
    }
73

74
    /**
75
     * Get the availale configuration.
76
     *
77
     * @return array<string, mixed>|mixed
78
     *
79
     * @phpstan-return ($key is null ? TWorkbenchConfig : mixed)
80
     */
81
    public static function config(?string $key = null): mixed
82
    {
83
        return ! \is_null($key)
16✔
84
            ? Arr::get(workbench(), $key)
9✔
85
            : workbench();
16✔
86
    }
87

88
    /**
89
     * Swap stub file by name.
90
     */
91
    public static function swapFile(string $name, ?string $file): void
92
    {
NEW
93
        if (\array_key_exists($name, static::$files)) {
×
NEW
94
            static::$files[$name] = $file;
×
95
        }
96
    }
97

98
    /**
99
     * Retrieve the stub file from name.
100
     */
101
    public static function stubFile(string $name): ?string
102
    {
103
        $defaultStub = join_paths(__DIR__, 'Console', 'stubs');
1✔
104

105
        return transform(
1✔
106
            Arr::get(array_merge([
1✔
107
                'config' => join_paths($defaultStub, 'testbench.yaml'),
1✔
108
                'config.basic' => join_paths($defaultStub, 'testbench.plain.yaml'),
1✔
109
                'gitignore' => join_paths($defaultStub, 'workbench.gitignore'),
1✔
110
                'routes.api' => join_paths($defaultStub, 'routes', 'api.php'),
1✔
111
                'routes.console' => join_paths($defaultStub, 'routes', 'console.php'),
1✔
112
                'routes.web' => join_paths($defaultStub, 'routes', 'web.php'),
1✔
113
                'seeders.database' => join_paths($defaultStub, 'database', 'seeders', 'DatabaseSeeder.php'),
1✔
114
            ], array_filter(static::$files)), $name),
1✔
115
            function ($file) {
1✔
116
                $realpath = realpath($file);
1✔
117

118
                return $realpath !== false ? $realpath : null;
1✔
119
            }
1✔
120
        );
1✔
121
    }
122
}
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