diff --git a/app/Listeners/NotifyFailedPlugin.php b/app/Listeners/NotifyFailedPlugin.php index af8bafc5..3d1c7f1f 100644 --- a/app/Listeners/NotifyFailedPlugin.php +++ b/app/Listeners/NotifyFailedPlugin.php @@ -3,6 +3,7 @@ namespace App\Listeners; use Event; +use App\Models\User; class NotifyFailedPlugin { @@ -10,15 +11,11 @@ class NotifyFailedPlugin { $plugin = $event->plugin; Event::listen(\App\Events\RenderingFooter::class, function ($event) use ($plugin) { + /** @var User */ $user = auth()->user(); if ($user && $user->isAdmin()) { - $options = json_encode([ - 'type' => 'error', - 'message' => trans('errors.plugins.boot', ['plugin' => trans($plugin->title)]), - 'duration' => 0, - 'showClose' => true, - ]); - $event->addContent(''); + $message = trans('errors.plugins.boot', ['plugin' => trans($plugin->title)]); + $event->addContent(""); } }); } diff --git a/app/Models/User.php b/app/Models/User.php index f033e37f..3efb24c2 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -34,7 +34,7 @@ class User extends Authenticatable implements JWTSubject protected $hidden = ['password', 'remember_token']; - public function isAdmin() + public function isAdmin(): bool { return $this->permission >= static::ADMIN; } diff --git a/app/Services/PluginManager.php b/app/Services/PluginManager.php index 0a29fa05..6cf7d4e0 100644 --- a/app/Services/PluginManager.php +++ b/app/Services/PluginManager.php @@ -243,13 +243,18 @@ class PluginManager $this->app->call($this->filesystem->getRequire($path), ['plugin' => $plugin]); } catch (\Throwable $th) { report($th); + $this->dispatcher->dispatch(new Events\PluginBootFailed($plugin)); + // @codeCoverageIgnoreStart + if (config('app.debug')) { + throw $th; + } + // @codeCoverageIgnoreEnd if (is_a($th, \Exception::class)) { $handler = $this->app->make(\App\Exceptions\Handler::class); if (!$handler->shouldReport($th)) { throw $th; } } - $this->dispatcher->dispatch(new Events\PluginBootFailed($plugin)); } } } diff --git a/tests/ListenersTest/NotifyFailedPluginTest.php b/tests/ListenersTest/NotifyFailedPluginTest.php index c2d35ea3..5d321b4d 100644 --- a/tests/ListenersTest/NotifyFailedPluginTest.php +++ b/tests/ListenersTest/NotifyFailedPluginTest.php @@ -3,6 +3,7 @@ namespace Tests; use App\Events; +use App\Models\User; use App\Services\Plugin; class NotifyFailedPluginTest extends TestCase @@ -16,14 +17,14 @@ class NotifyFailedPluginTest extends TestCase event(new Events\RenderingFooter($content)); $this->assertCount(0, $content); - $this->actAs('normal'); + $this->actingAs(factory(User::class)->make()); event(new Events\PluginBootFailed($plugin)); event(new Events\RenderingFooter($content)); $this->assertCount(0, $content); - $this->actAs('admin'); + $this->actingAs(factory(User::class)->states('admin')->make()); event(new Events\PluginBootFailed($plugin)); event(new Events\RenderingFooter($content)); - $this->assertStringContainsString('blessing.ui.message', $content[0]); + $this->assertStringContainsString('blessing.notify.toast', $content[0]); } }