From 57ef989df800940e317d4933da6937477df3a0e5 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 25 Jun 2024 22:02:23 +0100 Subject: [PATCH] feat(presets): improve laravel preset --- src/ArchPresets/Base.php | 2 - src/ArchPresets/Laravel.php | 74 +++++++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 5 deletions(-) diff --git a/src/ArchPresets/Base.php b/src/ArchPresets/Base.php index ad64459a..78446817 100644 --- a/src/ArchPresets/Base.php +++ b/src/ArchPresets/Base.php @@ -18,8 +18,6 @@ final class Base extends AbstractPreset 'debug_zval_dump', 'debug_backtrace', 'debug_print_backtrace', - 'dd', - 'ddd', 'dump', 'ray', 'die', diff --git a/src/ArchPresets/Laravel.php b/src/ArchPresets/Laravel.php index ce41ff6a..629d4777 100644 --- a/src/ArchPresets/Laravel.php +++ b/src/ArchPresets/Laravel.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace Pest\ArchPresets; +use Throwable; + /** * @internal */ @@ -15,37 +17,94 @@ final class Laravel extends AbstractPreset public function execute(): void { $this->expectations[] = expect([ + 'dd', + 'ddd', 'env', 'exit', ])->not->toBeUsed(); + $this->expectations[] = expect('App') + ->not->toBeEnums() + ->ignoring('App\Enums'); + + $this->expectations[] = expect('App\Enums') + ->toBeEnums(); + + $this->expectations[] = expect('App\Exceptions') + ->classes() + ->toImplement('Throwable'); + + $this->expectations[] = expect('App') + ->not->toImplement(Throwable::class) + ->ignoring('App\Exceptions'); + $this->expectations[] = expect('App\Http\Controllers') + ->classes() ->toHaveSuffix('Controller'); + $this->expectations[] = expect('App') + ->not->toHaveSuffix('Controller') + ->ignoring('App\Http\Controllers'); + $this->expectations[] = expect('App\Http\Middleware') + ->classes() ->toHaveMethod('handle'); $this->expectations[] = expect('App\Models') + ->classes() + ->toExtend('Illuminate\Database\Eloquent\Model') ->not->toHaveSuffix('Model'); + $this->expectations[] = expect('App') + ->not->toExtend('Illuminate\Database\Eloquent\Model') + ->ignoring('App\Models'); + $this->expectations[] = expect('App\Http\Requests') + ->classes() ->toHaveSuffix('Request') ->toExtend('Illuminate\Foundation\Http\FormRequest') // @phpstan-ignore-line ->toHaveMethod('rules'); + $this->expectations[] = expect('App') + ->not->toExtend('Illuminate\Foundation\Http\FormRequest') + ->ignoring('App\Http\Requests'); + $this->expectations[] = expect('App\Console\Commands') + ->classes() ->toHaveSuffix('Command') ->toExtend('Illuminate\Console\Command') // @phpstan-ignore-line ->toHaveMethod('handle'); - $this->expectations[] = expect('App\Exceptions') - ->toImplement('Throwable'); + $this->expectations[] = expect('App') + ->not->toExtend('Illuminate\Console\Command') + ->ignoring('App\Console\Commands'); $this->expectations[] = expect('App\Mail') + ->classes() ->toExtend('Illuminate\Mail\Mailable'); // @phpstan-ignore-line + $this->expectations[] = expect('App') + ->not->toExtend('Illuminate\Mail\Mailable') + ->ignoring('App\Mail'); + $this->expectations[] = expect('App\Jobs') - ->toHaveMethod('handle'); + ->classes() + ->toImplement('Illuminate\Contracts\Queue\ShouldQueue') + ->toUseTraits([ + 'Illuminate\Bus\Queueable', + 'Illuminate\Foundation\Bus\Dispatchable', + 'Illuminate\Queue\InteractsWithQueue', + 'Illuminate\Queue\SerializesModels', + ])->toHaveMethod('handle'); + + $this->expectations[] = expect('App') + ->not->toImplement('Illuminate\Contracts\Queue\ShouldQueue') + ->not->toUseTraits([ + 'Illuminate\Bus\Queueable', + 'Illuminate\Foundation\Bus\Dispatchable', + 'Illuminate\Queue\InteractsWithQueue', + 'Illuminate\Queue\SerializesModels', + ])->ignoring('App\Jobs'); $this->expectations[] = expect('App\Listeners') ->toHaveMethod('handle'); @@ -53,9 +112,18 @@ final class Laravel extends AbstractPreset $this->expectations[] = expect('App\Notifications') ->toExtend('Illuminate\Notifications\Notification'); // @phpstan-ignore-line + $this->expectations[] = expect('App') + ->not->toExtend('Illuminate\Notifications\Notification') + ->ignoring('App\Notifications'); + $this->expectations[] = expect('App\Providers') // @phpstan-ignore-line ->toHaveSuffix('ServiceProvider') ->toExtend('Illuminate\Support\ServiceProvider') // @phpstan-ignore-line ->not->toBeUsed(); + + $this->expectations[] = expect('App') + ->not->toExtend('Illuminate\Support\ServiceProvider') + ->not->toHaveSuffix('ServiceProvider') + ->ignoring('App\Providers'); } }