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

orchestral / canvas / 5937603488

22 Aug 2023 10:28AM UTC coverage: 94.387%. Remained the same
5937603488

push

github

crynobone
wip

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

1 of 1 new or added line in 1 file covered. (100.0%)

824 of 873 relevant lines covered (94.39%)

21.39 hits per line

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

83.93
/src/LaravelServiceProvider.php
1
<?php
2

3
namespace Orchestra\Canvas;
4

5
use Illuminate\Console\Application as Artisan;
6
use Illuminate\Contracts\Foundation\Application;
7
use Illuminate\Contracts\Support\DeferrableProvider;
8
use Illuminate\Filesystem\Filesystem;
9
use Illuminate\Support\Arr;
10
use Illuminate\Support\Env;
11
use Illuminate\Support\ServiceProvider;
12
use Orchestra\Canvas\Core\Presets\Preset;
13
use Orchestra\Workbench\Workbench;
14
use Symfony\Component\Yaml\Yaml;
15

16
use function Orchestra\Testbench\package_path;
17

18
class LaravelServiceProvider extends ServiceProvider implements DeferrableProvider
19
{
20
    use Core\CommandsProvider;
21

22
    /**
23
     * Register services.
24
     *
25
     * @return void
26
     */
27
    public function register()
28
    {
29
        $this->app->singleton('orchestra.canvas', function (Application $app) {
91✔
30
            $filesystem = $app->make('files');
70✔
31

32
            if (\defined('TESTBENCH_WORKING_PATH') && class_exists(Workbench::class)) {
70✔
33
                return $this->registerCanvasForWorkbench($filesystem);
×
34
            }
35

36
            $config = ['preset' => 'laravel'];
70✔
37

38
            if ($filesystem->exists($app->basePath('canvas.yaml'))) {
70✔
39
                $config = Yaml::parseFile($app->basePath('canvas.yaml'));
×
40
            } else {
41
                Arr::set($config, 'testing.extends', [
70✔
42
                    'unit' => 'PHPUnit\Framework\TestCase',
70✔
43
                    'feature' => 'Tests\TestCase',
70✔
44
                ]);
70✔
45

46
                $config['namespace'] = trim($this->app->getNamespace(), '\\');
70✔
47
            }
48

49
            $config['user-auth-provider'] = $this->userProviderModel();
70✔
50

51
            return Canvas::preset($config, $app->basePath(), $filesystem);
70✔
52
        });
91✔
53
    }
54

55
    /**
56
     * Bootstrap services.
57
     *
58
     * @return void
59
     */
60
    public function boot()
61
    {
62
        Artisan::starting(static function ($artisan) {
91✔
63
            $artisan->getLaravel()->booted(static function ($app) use ($artisan) {
90✔
64
                /**
65
                 * @var \Illuminate\Contracts\Foundation\Application $app
66
                 * @var \Illuminate\Console\Application $artisan
67
                 */
68
                $preset = $app->make('orchestra.canvas');
90✔
69

70
                if (
71
                    \defined('TESTBENCH_WORKING_PATH')
90✔
72
                    || Env::get('CANVAS_FOR_LARAVEL') === true
90✔
73
                    || file_exists($app->basePath('canvas.yaml'))
90✔
74
                ) {
75
                    $artisan->add(new Commands\Channel($preset));
90✔
76
                    $artisan->add(new Commands\Component($preset));
90✔
77
                    $artisan->add(new Commands\Console($preset));
90✔
78
                    $artisan->add(new Commands\Event($preset));
90✔
79
                    $artisan->add(new Commands\Exception($preset));
90✔
80
                    $artisan->add(new Commands\Database\Cast($preset));
90✔
81
                    $artisan->add(new Commands\Database\Eloquent($preset));
90✔
82
                    $artisan->add(new Commands\Database\Factory($preset));
90✔
83
                    $artisan->add(new Commands\Database\Migration($preset));
90✔
84
                    $artisan->add(new Commands\Database\Observer($preset));
90✔
85
                    $artisan->add(new Commands\Database\Seeder($preset));
90✔
86
                    $artisan->add(new Commands\Job($preset));
90✔
87
                    $artisan->add(new Commands\Listener($preset));
90✔
88
                    $artisan->add(new Commands\Mail($preset));
90✔
89
                    $artisan->add(new Commands\Notification($preset));
90✔
90
                    $artisan->add(new Commands\Policy($preset));
90✔
91
                    $artisan->add(new Commands\Provider($preset));
90✔
92
                    $artisan->add(new Commands\Request($preset));
90✔
93
                    $artisan->add(new Commands\Resource($preset));
90✔
94
                    $artisan->add(new Commands\Routing\Controller($preset));
90✔
95
                    $artisan->add(new Commands\Routing\Middleware($preset));
90✔
96
                    $artisan->add(new Commands\Rule($preset));
90✔
97
                    $artisan->add(new Commands\StubPublish($preset));
90✔
98
                    $artisan->add(new Commands\Testing($preset));
90✔
99
                }
100

101
                $preset->addAdditionalCommands($artisan);
90✔
102
            });
90✔
103
        });
91✔
104
    }
105

106
    /**
107
     * Regiseter canvas for workbench.
108
     */
109
    protected function registerCanvasForWorkbench(Filesystem $filesystem): Preset
110
    {
111
        $config = ['preset' => Presets\PackageWorkbench::class];
×
112

113
        if ($filesystem->exists(package_path('canvas.yaml'))) {
×
114
            $yaml = Yaml::parseFile(package_path('canvas.yaml'));
×
115

116
            $config['generators'] = $yaml['generators'] ?? [];
×
117
        }
118

119
        return Canvas::preset(
×
120
            $config, rtrim(package_path(), DIRECTORY_SEPARATOR), $filesystem
×
121
        );
×
122
    }
123

124
    /**
125
     * Get the services provided by the provider.
126
     *
127
     * @return array<int, string>
128
     */
129
    public function provides()
130
    {
131
        return ['orchestra.canvas'];
1✔
132
    }
133
}
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