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

orchestral / workbench / 11473929668

23 Oct 2024 05:56AM UTC coverage: 91.379% (+0.2%) from 91.139%
11473929668

push

github

crynobone
wip

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

22 of 23 new or added lines in 1 file covered. (95.65%)

159 of 174 relevant lines covered (91.38%)

7.18 hits per line

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

96.55
/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
 *   seeder.database: ?string
23
 * }
24
 */
25
class Workbench
26
{
27
    /**
28
     * Files of stub files overrides.
29
     *
30
     * @var array<string, ?string>
31
     * @phpstan-var TStubFiles
32
     */
33
    protected static array $files = [
34
        'config' => null,
35
        'config.basic' => null,
36
        'gitignore' => null,
37
        'routes.api' => null,
38
        'routes.console' => null,
39
        'routes.web' => null,
40
        'seeders.database' => null,
41
    ];
42

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

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

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

73
    /**
74
     * Get the availale configuration.
75
     *
76
     * @param  string|null  $key
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
        static::$files[$name] = $file;
×
94
    }
95

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

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

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