Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Setting;
use App\User;
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
use Illuminate\Contracts\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
Expand All @@ -33,7 +34,8 @@ public function boot(): void

$this->setupDatabase();

if (! is_file(public_path('storage/.gitignore'))) {
// Check the link itself; the Docker image doesn't ship storage/app/public/.gitignore.
if (! file_exists(public_path('storage'))) {
Artisan::call('storage:link');
\Session::put('current_user', null);
}
Expand Down Expand Up @@ -136,6 +138,15 @@ public function genKey(): void
*/
public function register(): void
{
// The framework only adds these paths once providers have booted, but
// an Artisan::call() in boot() loads the console commands before
// then, which dropped register:app (#1606). Add them up front.
if ($this->app->runningInConsole()) {
$this->app->make(ConsoleKernel::class)
->addCommandPaths([app_path('Console/Commands')])
->addCommandRoutePaths([base_path('routes/console.php')]);
}

if ($this->app->isLocal()) {
$this->app->register(IdeHelperServiceProvider::class);
}
Expand Down
30 changes: 30 additions & 0 deletions tests/Feature/ConsoleCommandsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Tests\Feature;

use Illuminate\Console\Command;
use Illuminate\Contracts\Console\Kernel;
use Tests\TestCase;

/**
* Guards against #1606: an Artisan call in AppServiceProvider::boot() dropped
* the commands in app/Console/Commands. The test database is always fresh, so
* every test boot runs the boot-time migrate that triggers it.
*/
class ConsoleCommandsTest extends TestCase
{
public function test_every_command_in_app_console_commands_is_registered(): void
{
$registered = array_map('get_class', $this->app->make(Kernel::class)->all());

$files = glob(app_path('Console/Commands/*.php'));
$this->assertNotEmpty($files);

foreach ($files as $file) {
$class = 'App\\Console\\Commands\\'.basename($file, '.php');
if (is_subclass_of($class, Command::class)) {
$this->assertContains($class, $registered);
}
}
}
}
Loading