Skip to content

Commit

Permalink
added test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenjude committed Sep 12, 2024
1 parent f673569 commit 613dace
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 54 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
43 changes: 21 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
15 changes: 10 additions & 5 deletions src/DebuggerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -45,6 +49,7 @@ public function register(Panel $panel): void {
]));
}

public function boot(Panel $panel): void {
public function boot(Panel $panel): void
{
}
}
1 change: 0 additions & 1 deletion src/DebuggerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Stephenjude\FilamentDebugger\Commands\DebuggerCommand;

class DebuggerServiceProvider extends PackageServiceProvider
{
Expand Down
6 changes: 3 additions & 3 deletions src/Traits/HasGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
}
}
4 changes: 2 additions & 2 deletions src/Traits/HasHorizon.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ trait HasHorizon
{
use EvaluatesClosures;

public Closure|bool $hasHorizon = true;
public Closure | bool $hasHorizon = true;

public string $horizonLabel;

public string $horizonIcon;

public string $horizonUrl;

public bool $horizonOpenInNewTab = true;
public Closure | bool $horizonOpenInNewTab = true;

private function getHorizonNavigation(): NavigationItem {
return NavigationItem::make()
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HasPulse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HasTelescope.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait HasTelescope
{
use EvaluatesClosures;

public Closure|bool $hasTelescope;
public Closure|bool $hasTelescope = true;

public string $telescopeLabel;

Expand Down
42 changes: 42 additions & 0 deletions tests/Common/AdminPanelProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Stephenjude\FilamentDebugger\Tests\Common;

use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Panel;
use Filament\PanelProvider;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;

class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->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,
]);
}
}
132 changes: 122 additions & 10 deletions tests/DebuggerTest.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,131 @@
<?php

use Filament\Navigation\NavigationItem;
use Stephenjude\FilamentDebugger\DebuggerPlugin;

it('can install configurations', function () {
$this->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();
});
Loading

0 comments on commit 613dace

Please sign in to comment.