diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 175647b..7485798 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -65,6 +65,10 @@ jobs: # Docs: = 8.0 + run: composer require --dev spatie/laravel-ignition + - name: Show most important package versions run: composer info | grep -e laravel -e spiral -e phpunit/phpunit -e phpstan/phpstan diff --git a/CHANGELOG.md b/CHANGELOG.md index 0641b91..57e9d31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver]. +## UNRELEASED + +### Added + +- Integration with [spatie/laravel-ignition](https://github.com/spatie/laravel-ignition) is supported now [#88] +- Defining of environment variable `APP_RUNNING_IN_CONSOLE` in the worker "binary" file (it is required for the correct [`Application::runningInConsole`](https://bit.ly/3GPJTNL) method working) [#88] + +### Fixed + +- CLI running mode detection [#88] + +[#88]:https://github.com/spiral/roadrunner-laravel/pull/88 + ## v5.8.0 ### Added diff --git a/bin/rr-worker b/bin/rr-worker index 230a2e6..583b38d 100755 --- a/bin/rr-worker +++ b/bin/rr-worker @@ -7,6 +7,19 @@ declare(strict_types=1); \ini_set('display_errors', 'stderr'); +/* +|-------------------------------------------------------------------------- +| Setup Application Running Mode +|-------------------------------------------------------------------------- +| +| Saying to the Laravel "We are NOT running in the console" +| (https://bit.ly/3GPJTNL). +| +*/ + +$_ENV['APP_RUNNING_IN_CONSOLE'] = false; +\putenv('APP_RUNNING_IN_CONSOLE=false'); + /* |-------------------------------------------------------------------------- | Register The Auto Loader diff --git a/phpstan.neon.dist b/phpstan.neon.dist index d3ecd81..238ecb4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,7 +6,9 @@ parameters: - fixes - helpers - src - reportUnmatchedIgnoredErrors: true + reportUnmatchedIgnoredErrors: false ignoreErrors: - message: '#Call to protected method bootstrappers\(\) of class.+Kernel#' paths: [src/Application/Factory.php] + - message: '#Class Spatie\\.+Ignition.* not found#' + paths: [src/Listeners/ResetLaravelIgnitionListener.php] diff --git a/src/Defaults.php b/src/Defaults.php index 4e8f4e1..bfad7c0 100644 --- a/src/Defaults.php +++ b/src/Defaults.php @@ -57,6 +57,7 @@ public static function beforeLoopIteration(): array Listeners\ResetInertiaListener::class, // for Listeners\ResetZiggyListener::class, // for Listeners\ResetLivewireListener::class, // for + Listeners\ResetLaravelIgnitionListener::class, // for ]; } diff --git a/src/Dumper/Dumper.php b/src/Dumper/Dumper.php index 60f5f09..2d4d949 100644 --- a/src/Dumper/Dumper.php +++ b/src/Dumper/Dumper.php @@ -101,6 +101,10 @@ public function dd(...$vars) */ protected function ranUsingCLI(): bool { + if (Env::get('APP_RUNNING_IN_CONSOLE') === true) { + return true; + } + /** @link https://roadrunner.dev/docs/php-environment */ if (Env::get('RR_MODE') !== null && Env::get('RR_RELAY') !== null) { return false; diff --git a/src/Listeners/ResetLaravelIgnitionListener.php b/src/Listeners/ResetLaravelIgnitionListener.php new file mode 100644 index 0000000..4534262 --- /dev/null +++ b/src/Listeners/ResetLaravelIgnitionListener.php @@ -0,0 +1,58 @@ +. + */ +class ResetLaravelIgnitionListener implements ListenerInterface +{ + use Traits\InvokerTrait; + + /** + * @var array + */ + private static array $abstracts = [ + \Spatie\Ignition\Ignition::class, + \Spatie\LaravelIgnition\Support\SentReports::class, + \Spatie\LaravelIgnition\Recorders\DumpRecorder\DumpRecorder::class, + \Spatie\LaravelIgnition\Recorders\LogRecorder\LogRecorder::class, + \Spatie\LaravelIgnition\Recorders\QueryRecorder\QueryRecorder::class, + \Spatie\LaravelIgnition\Recorders\JobRecorder\JobRecorder::class, + ]; + + /** + * {@inheritdoc} + */ + public function handle($event): void + { + if (!\class_exists(\Spatie\LaravelIgnition\IgnitionServiceProvider::class)) { + return; + } + + if ($event instanceof WithApplication) { + $app = $event->application(); + + /** @see \Spatie\LaravelIgnition\IgnitionServiceProvider::resetFlareAndLaravelIgnition */ + foreach (self::$abstracts as $abstract) { + if ($app->resolved($abstract)) { + $instance = $app->make($abstract); + + if (!\is_object($instance)) { + continue; + } + + foreach (['reset', 'clear'] as $method_name) { + if ($this->invokeMethod($instance, $method_name)) { + break; + } + } + } + } + } + } +} diff --git a/tests/Unit/Listeners/ResetLaravelIgnitionListenerTest.php b/tests/Unit/Listeners/ResetLaravelIgnitionListenerTest.php new file mode 100644 index 0000000..7c284d6 --- /dev/null +++ b/tests/Unit/Listeners/ResetLaravelIgnitionListenerTest.php @@ -0,0 +1,67 @@ +markTestSkipped("Run 'composer require --dev spatie/laravel-ignition' for enabling this test"); + } + + $this->spy(\Spatie\Ignition\Ignition::class, function (m\MockInterface $m) { + $m->shouldReceive('reset')->once(); + }); + + $this->spy(\Spatie\LaravelIgnition\Support\SentReports::class, function (m\MockInterface $m) { + $m->shouldReceive('clear')->once(); + }); + + $this->spy(Recorders\DumpRecorder\DumpRecorder::class, function (m\MockInterface $m) { + $m->shouldReceive('reset')->once(); + }); + + $this->spy(Recorders\LogRecorder\LogRecorder::class, function (m\MockInterface $m) { + $m->shouldReceive('reset')->once(); + }); + + $this->spy(Recorders\QueryRecorder\QueryRecorder::class, function (m\MockInterface $m) { + $m->shouldReceive('reset')->once(); + }); + + $this->spy(Recorders\JobRecorder\JobRecorder::class, function (m\MockInterface $m) { + $m->shouldReceive('reset')->once(); + }); + + /** @var m\MockInterface|WithApplication $event_mock */ + $event_mock = m::mock(WithApplication::class) + ->makePartial() + ->expects('application') + ->andReturn($this->app) + ->getMock(); + + $this->listenerFactory()->handle($event_mock); + } + + /** + * @return ResetLaravelIgnitionListener + */ + protected function listenerFactory(): ResetLaravelIgnitionListener + { + return new ResetLaravelIgnitionListener(); + } +}