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

orchestral / workbench / 11553054117

28 Oct 2024 11:32AM UTC coverage: 90.449% (-0.4%) from 90.857%
11553054117

push

github

web-flow
[7.x] Add `Orchestra\Workbench\StubRegistrar` class (#38)

* wip

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

* wip

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

* wip

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

---------

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

18 of 21 new or added lines in 2 files covered. (85.71%)

161 of 178 relevant lines covered (90.45%)

8.65 hits per line

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

88.89
/src/StubRegistrar.php
1
<?php
2

3
namespace Orchestra\Workbench;
4

5
use Illuminate\Support\Arr;
6

7
use function Orchestra\Testbench\join_paths;
8

9
/**
10
 * @phpstan-type TStubFiles array{
11
 *   config: ?string,
12
 *   'config.basic': ?string,
13
 *   gitignore: ?string,
14
 *   'routes.api': ?string,
15
 *   'routes.console': ?string,
16
 *   'routes.web': ?string,
17
 *   'seeders.database': ?string
18
 * }
19
 */
20
class StubRegistrar
21
{
22
    /**
23
     * Files of stub files overrides.
24
     *
25
     * @var array<string, ?string>
26
     *
27
     * @phpstan-var TStubFiles
28
     */
29
    protected static array $files = [
30
        'config' => null,
31
        'config.basic' => null,
32
        'gitignore' => null,
33
        'routes.api' => null,
34
        'routes.console' => null,
35
        'routes.web' => null,
36
        'seeders.database' => null,
37
    ];
38

39
    /**
40
     * Swap stub file by name.
41
     */
42
    public function swap(string $name, ?string $file): void
43
    {
NEW
44
        if (\array_key_exists($name, static::$files)) {
×
NEW
45
            static::$files[$name] = $file;
×
46
        }
47
    }
48

49
    /**
50
     * Retrieve the stub file from name.
51
     */
52
    public static function file(string $name): ?string
53
    {
54
        $defaultStub = join_paths(__DIR__, 'Console', 'stubs');
8✔
55

56
        return transform(
8✔
57
            Arr::get(array_merge([
8✔
58
                'config' => join_paths($defaultStub, 'testbench.yaml'),
8✔
59
                'config.basic' => join_paths($defaultStub, 'testbench.plain.yaml'),
8✔
60
                'gitignore' => join_paths($defaultStub, 'workbench.gitignore'),
8✔
61
                'routes.api' => join_paths($defaultStub, 'routes', 'api.php'),
8✔
62
                'routes.console' => join_paths($defaultStub, 'routes', 'console.php'),
8✔
63
                'routes.web' => join_paths($defaultStub, 'routes', 'web.php'),
8✔
64
                'seeders.database' => join_paths($defaultStub, 'database', 'seeders', 'DatabaseSeeder.php'),
8✔
65
            ], array_filter(static::$files)), $name),
8✔
66
            function ($file) {
8✔
67
                $realpath = realpath($file);
8✔
68

69
                return $realpath !== false ? $realpath : null;
8✔
70
            }
8✔
71
        );
8✔
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

© 2025 Coveralls, Inc