diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e1423f0..5e4479a 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,16 +13,18 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.1, 8.2] - laravel: [8.*, 9.*, 10.*] + php: [8.2, 8.3] + laravel: [10.*, 11.*] stability: [prefer-stable] include: - - laravel: 8.* - testbench: ^6.0 - - laravel: 9.* - testbench: ^7.0 - laravel: 10.* testbench: ^8.0 + carbon: 3.* + collision: 8.* + - laravel: 11.* + testbench: ^9.0 + carbon: 2.* + collision: 7.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/README.md b/README.md index d09452c..5ce4b36 100644 --- a/README.md +++ b/README.md @@ -17,38 +17,37 @@ You can install the package via composer: composer require stephenjude/filament-debugger ``` -Run the setup command using +## Usages +```php +public function panel(Panel $panel): Panel +{ + use Stephenjude\FilamentDebugger\DebuggerPlugin; -```bash -php artisan filament-debugger:install + return $panel + ->plugin( + DebuggerPlugin::make() + ); +} ``` -This is the contents of the published config file: - -```php -return [ - 'debuggers' => [ - 'horizon', - 'telescope' - ], +### Telescope +Telescope provides insight into the requests coming into your application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps, and more. [Documentation](https://laravel.com/docs/9.x/telescope). - 'authorization' => false, +You can customize all the supported debuggers: - 'permissions' => [ - 'horizon' => 'horizon.view', - 'telescope' => 'telescope.view', - ], -]; +```php + use Stephenjude\FilamentDebugger\DebuggerPlugin; + return $panel + ->plugin( + DebuggerPlugin::make() + ->telescopeNavigation(true, 'Telescope', 'heroicon-o-sparkles', 'telescope', true) + ); ``` -## Debuggers -This package comes with first party Laravel packages for development and monitoring your Laravel application. - -### Laravel Telescope -Telescope provides insight into the requests coming into your application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps, and more. [Documentation](https://laravel.com/docs/9.x/telescope). ### Laravel Horizon Horizon allows you to easily monitor key metrics of your queue system such as job throughput, runtime, and job failures. [Documentation](https://laravel.com/docs/9.x/horizon). + ## Usage Now you can view the installed debuggers when you log in into your filament admin panel. diff --git a/composer.json b/composer.json index 375bd4f..ff757d2 100644 --- a/composer.json +++ b/composer.json @@ -24,9 +24,10 @@ "require-dev": { "laravel/pint": "^1.17", "nunomaduro/collision": "^8.0", - "orchestra/testbench": "^8.0", + "orchestra/testbench": "^9.0", "pestphp/pest": "^3.0", "pestphp/pest-plugin-laravel": "^3.0", + "pestphp/pest-plugin-livewire": "^3.0", "phpunit/phpunit": "^11.0" }, "autoload": { diff --git a/src/DebuggerPlugin.php b/src/DebuggerPlugin.php index 2458c18..e6e8154 100755 --- a/src/DebuggerPlugin.php +++ b/src/DebuggerPlugin.php @@ -18,22 +18,26 @@ class DebuggerPlugin implements Plugin use HasPulse; use HasTelescope; - public static function make(): static { + public static function make(): static + { return app(static::class); } - public static function get(): static { + public static function get(): static + { /** @var static $plugin */ $plugin = filament(app(static::class)->getId()); return $plugin; } - public function getId(): string { + public function getId(): string + { return 'filament-debugger'; } - public function register(Panel $panel): void { + public function register(Panel $panel): void + { if ($this->authorized() === false) { return; } @@ -45,6 +49,7 @@ public function register(Panel $panel): void { ])); } - public function boot(Panel $panel): void { + public function boot(Panel $panel): void + { } } diff --git a/src/DebuggerServiceProvider.php b/src/DebuggerServiceProvider.php index 1f3ff06..b4d5d01 100644 --- a/src/DebuggerServiceProvider.php +++ b/src/DebuggerServiceProvider.php @@ -4,7 +4,6 @@ use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; -use Stephenjude\FilamentDebugger\Commands\DebuggerCommand; class DebuggerServiceProvider extends PackageServiceProvider { diff --git a/src/Traits/HasGroup.php b/src/Traits/HasGroup.php index 9103723..ecff36a 100755 --- a/src/Traits/HasGroup.php +++ b/src/Traits/HasGroup.php @@ -11,7 +11,7 @@ trait HasGroup public Closure|bool $groupNavigation = true; - public string $groupNavigationLabel; + public string $groupNavigationLabel = 'Debuggers'; public function groupNavigation(Closure|bool $condition = true, string $label = 'Debugger'): static { @@ -24,11 +24,11 @@ public function groupNavigation(Closure|bool $condition = true, string $label = public function hasGroupNavigation(): bool { - return $this->evaluate($this->groupNavigation ?? true) === true; + return $this->evaluate($this->groupNavigation) === true; } public function getGroupNavigationLabel(): string { - return $this->groupNavigationLabel ?? 'Debuggers'; + return $this->groupNavigationLabel; } } diff --git a/src/Traits/HasHorizon.php b/src/Traits/HasHorizon.php index 8ca8cab..054ea8f 100755 --- a/src/Traits/HasHorizon.php +++ b/src/Traits/HasHorizon.php @@ -10,7 +10,7 @@ trait HasHorizon { use EvaluatesClosures; - public Closure|bool $hasHorizon = true; + public Closure | bool $hasHorizon = true; public string $horizonLabel; @@ -18,7 +18,7 @@ trait HasHorizon public string $horizonUrl; - public bool $horizonOpenInNewTab = true; + public Closure | bool $horizonOpenInNewTab = true; private function getHorizonNavigation(): NavigationItem { return NavigationItem::make() diff --git a/src/Traits/HasPulse.php b/src/Traits/HasPulse.php index 801c6aa..b9ae254 100755 --- a/src/Traits/HasPulse.php +++ b/src/Traits/HasPulse.php @@ -18,7 +18,7 @@ trait HasPulse public string $pulseUrl; - public Closure|bool $pulseOpenInNewTab; + public Closure|bool $pulseOpenInNewTab = true; public function pulseNavigation( Closure|bool $condition = true, diff --git a/src/Traits/HasTelescope.php b/src/Traits/HasTelescope.php index 16b4467..71b25c7 100755 --- a/src/Traits/HasTelescope.php +++ b/src/Traits/HasTelescope.php @@ -10,7 +10,7 @@ trait HasTelescope { use EvaluatesClosures; - public Closure|bool $hasTelescope; + public Closure|bool $hasTelescope = true; public string $telescopeLabel; diff --git a/tests/Common/AdminPanelProvider.php b/tests/Common/AdminPanelProvider.php new file mode 100644 index 0000000..5afeb83 --- /dev/null +++ b/tests/Common/AdminPanelProvider.php @@ -0,0 +1,42 @@ +default() + ->id('admin') + ->path('admin') + ->login() + ->middleware([ + EncryptCookies::class, + AddQueuedCookiesToResponse::class, + StartSession::class, + AuthenticateSession::class, + ShareErrorsFromSession::class, + VerifyCsrfToken::class, + SubstituteBindings::class, + DisableBladeIconComponents::class, + DispatchServingFilamentEvent::class, + ]) + ->authMiddleware([ + Authenticate::class, + ]); + } +} diff --git a/tests/DebuggerTest.php b/tests/DebuggerTest.php index c9ad9e1..08ff7c2 100644 --- a/tests/DebuggerTest.php +++ b/tests/DebuggerTest.php @@ -1,19 +1,131 @@ artisan('filament-debugger:install') - ->expectsOutput('Laravel Horizon installed.') - ->expectsOutput('Laravel Telescope installed.') - ->expectsOutput('Filament Debugger Installed.') - ->assertExitCode(0); +it('will not use debugging functions') + ->expect(['dd', 'dump', 'ddd']) + ->each->not->toBeUsed(); + +it('registers plugin', function () { + $panel = filament()->getCurrentPanel()->plugin(DebuggerPlugin::make()); + + expect($panel->getPlugin('filament-debugger')) + ->not() + ->toThrow(Exception::class); + + expect($panel->getNavigationItems())->toHaveCount(3); + + $plugin = $panel->getPlugin('filament-debugger'); + + expect($plugin)->hasHorizon()->toBeTrue(); + + expect($plugin)->hasTelescope()->toBeTrue(); + + expect($plugin)->hasPulse()->toBeTrue(); }); -it('can open horizon', function () { - $this->get(DebuggerPlugin::horizonNavigation())->assertSuccessful(); +it('authorizes plugin', function () { + $panel = filament()->getCurrentPanel()->plugin(DebuggerPlugin::make()->authorize(false)); + + expect($panel->getNavigationItems())->toHaveCount(0); }); -it('can open telescope', function () { - $this->get(DebuggerPlugin::telescopeNavigation())->assertSuccessful(); +it('groups plugin navigation items', function () { + $panel = filament()->getCurrentPanel() + ->plugin( + DebuggerPlugin::make()->groupNavigation( + condition: fn() => true, + label: 'Laravel Debuggers' + ) + ); + + collect($panel->getNavigationItems()) + ->each( + fn(NavigationItem $navigationItem) => expect($navigationItem)->getGroup()->toBe('Laravel Debuggers') + ); +}); + +it('customizes telescope navigation', function () { + $panel = filament()->getCurrentPanel()->plugin( + DebuggerPlugin::make() + ->horizonNavigation(false) + ->pulseNavigation(false) + ->telescopeNavigation( + condition: fn() => true, + label: 'Laravel Telescope', + icon: 'heroicon-o-users', + url: 'telescope/requests', + openInNewTab: fn() => false + ) + ); + + expect($panel->getNavigationItems())->toHaveCount(1); + + /** @var NavigationItem $navigationItem */ + $navigationItem = $panel->getNavigationItems()[0]; + + expect($navigationItem)->getLabel()->toBe('Laravel Telescope'); + + expect($navigationItem)->getIcon()->toBe('heroicon-o-users'); + + expect($navigationItem)->getUrl()->toBe('telescope/requests'); + + expect($navigationItem)->shouldOpenUrlInNewTab()->toBeFalse(); +}); + +it('customizes horizon navigation', function () { + $panel = filament()->getCurrentPanel()->plugin( + DebuggerPlugin::make() + ->telescopeNavigation(false) + ->pulseNavigation(false) + ->horizonNavigation( + condition: fn() => true, + label: 'Laravel Horizon', + icon: 'heroicon-o-users', + url: url('horizon/requests'), + openInNewTab: fn() => false + ) + ); + + expect($panel->getNavigationItems())->toHaveCount(1); + + /** @var NavigationItem $navigationItem */ + $navigationItem = $panel->getNavigationItems()[0]; + + expect($navigationItem)->getLabel()->toBe('Laravel Horizon'); + + expect($navigationItem)->getIcon()->toBe('heroicon-o-users'); + + expect($navigationItem)->getUrl()->toBe(url('horizon/requests')); + + expect($navigationItem)->shouldOpenUrlInNewTab()->toBeFalse(); +}); + +it('customizes pulse navigation', function () { + $panel = filament()->getCurrentPanel()->plugin( + DebuggerPlugin::make() + ->horizonNavigation(false) + ->telescopeNavigation(false) + ->pulseNavigation( + condition: fn() => true, + label: 'Laravel Pulse', + icon: 'heroicon-o-users', + url: 'pulse/requests', + openInNewTab: fn() => false + ) + ); + + expect($panel->getNavigationItems())->toHaveCount(1); + + /** @var NavigationItem $navigationItem */ + $navigationItem = $panel->getNavigationItems()[0]; + + expect($navigationItem)->getLabel()->toBe('Laravel Pulse'); + + expect($navigationItem)->getIcon()->toBe('heroicon-o-users'); + + expect($navigationItem)->getUrl()->toBe('pulse/requests'); + + expect($navigationItem)->shouldOpenUrlInNewTab()->toBeFalse(); }); diff --git a/tests/TestCase.php b/tests/TestCase.php index e929a91..a62ff6f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -10,6 +10,7 @@ use Livewire\LivewireServiceProvider; use Orchestra\Testbench\TestCase as Orchestra; use Stephenjude\FilamentDebugger\DebuggerServiceProvider; +use Stephenjude\FilamentDebugger\Tests\Common\AdminPanelProvider; class TestCase extends Orchestra { @@ -25,9 +26,8 @@ protected function getPackageProviders($app) BladeIconsServiceProvider::class, FilamentServiceProvider::class, LivewireServiceProvider::class, - TelescopeServiceProvider::class, - HorizonServiceProvider::class, DebuggerServiceProvider::class, + AdminPanelProvider::class, ]; }