-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.3] Use bootstrappers instead of events #16012
Conversation
Nice idea. |
Hello, This was a breaking change on my application. Reverting back locally to 5.3.19 made the tests pass again so I could pinpoint to issue to something done in between those releases. I stumbled upon this PR. $events = $this->app['events'];
$events->listen(ArtisanStarting::class, function ($event) use ($commands) {
$event->artisan->resolveCommands($commands);
}); It works. But when using the updated version Artisan::starting(function ($artisan) use ($commands) {
$artisan->resolveCommands($commands);
}); It fails. I don't understand why though. Something in particular that could point me in the right direction ? Thanks, |
public static function starting(\Closure $callback) | ||
{ | ||
static::$bootstrappers[] = $callback; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should automatically run $callback
when calling starting()
after Illuminate\Console\Events\ArtisanStarting
has been called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Illuminate\Foundation\Console\Kernel::registerCommand()
will resolve Illuminate\Console\Application
when it call getArtisan()
, if any part of the code execute this too early (before all events registered) it's not going to be called again.
@nWidart how do you register the |
Hello, thanks for answering. It's registered here: https://github.com/Idavoll/Media/blob/2.0/Providers/MediaServiceProvider.php#L97 $this->app->singleton('command.media.refresh', function ($app) {
return new RefreshThumbnailCommand($app['Modules\Media\Repositories\FileRepository']);
});
$this->commands('command.media.refresh'); About the Thanks, |
The error means |
This PR makes my tests 50% slower because the bootstrappers keep stacking up for each test case. If I implement clearing the bootstrappers like this after each test case, the tests run as fast as before. @themsaid can you please have a look at the changes and see if it makes sense? I'll open a PR then. Edit: I can just as well create the PR right away and continue the discussion there. |
This PR switches to using a static object to collect console application bootstrappers that needs to run on starting Artisan, this is an attempt to deal with the situation where you use
$this->withoutEvents();
while running tests & try to call a console command which will attempt to listen to the ArtisanStarting event, but since the Dispatcher is mocked no events get fired.