From 3f9f400c750c3e3bb6637e61c3f621177fa192bd Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Tue, 22 Apr 2025 22:06:20 +0200 Subject: [PATCH] test: improve ArchTest - add more rules for the entire app - add Resources rule - improve existing rules - adjust formatting --- tests/ArchTest.php | 55 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/tests/ArchTest.php b/tests/ArchTest.php index c9c8e64ea..42a74b7a4 100644 --- a/tests/ArchTest.php +++ b/tests/ArchTest.php @@ -16,22 +16,32 @@ arch('App') ->ignoring('App\Enums') ->not->toImplement(Throwable::class) ->ignoring('App\Exceptions') - ->not->toExtend('Illuminate\Database\Eloquent\Model') + ->not->toExtend(\Illuminate\Database\Eloquent\Model::class) ->ignoring('App\Models') - ->not->toExtend('Illuminate\Foundation\Http\FormRequest') + ->not->toExtend(\Illuminate\Foundation\Http\FormRequest::class) ->ignoring('App\Http\Requests') - ->not->toExtend('Illuminate\Console\Command') + ->not->toExtend(\Illuminate\Console\Command::class) ->ignoring('App\Console\Commands') - ->not->toExtend('Illuminate\Mail\Mailable') + ->not->toExtend(\Illuminate\Mail\Mailable::class) ->ignoring('App\Mail') - ->not->toExtend('Illuminate\Notifications\Notification') + ->not->toExtend(\Illuminate\Notifications\Notification::class) ->ignoring('App\Notifications') - ->not->toExtend('Illuminate\Support\ServiceProvider') + ->not->toExtend(\Illuminate\Support\ServiceProvider::class) ->ignoring('App\Providers') ->not->toHaveSuffix('ServiceProvider') ->ignoring('App\Providers') ->not->toHaveSuffix('Controller') - ->ignoring('App\Http\Controllers'); + ->ignoring('App\Http\Controllers') + ->not->toImplement(\Illuminate\Contracts\Queue\ShouldQueue::class) + ->ignoring('App\Jobs') + ->not->toUseTrait(\Illuminate\Foundation\Bus\Dispatchable::class) + ->ignoring('App\Jobs') + ->not->toExtend(\Illuminate\Http\Resources\Json\JsonResource::class) + ->ignoring('App\Http\Resources') + ->not->toExtend(\Illuminate\Http\Resources\Json\ResourceCollection::class) + ->ignoring('App\Http\Resources') + ->not->toUseTrait(\Illuminate\Queue\SerializesModels::class) + ->ignoring('App\Events'); arch('Actions') ->expect('App\Actions') @@ -40,7 +50,7 @@ arch('Actions') ->toImplementNothing() ->not->toHavePublicMethodsBesides(['handle']) ->toHaveLineCountLessThan(250) - ->not->toHaveSuffix('Action'); + ->toHaveSuffix('Action'); arch('Concerns') ->expect('App\Concerns') @@ -53,7 +63,7 @@ arch('Concerns') arch('Commands') ->expect('App\Console\Commands') ->toBeClasses() - ->toExtend('Illuminate\Console\Command') + ->toExtend(\Illuminate\Console\Command::class) ->toImplementNothing() ->not->toHavePublicMethodsBesides(['handle']) ->toHaveLineCountLessThan(150) @@ -85,6 +95,7 @@ arch('Events') ->expect('App\Events') ->toBeClasses() ->toExtendNothing() + ->toUseTrait(\Illuminate\Queue\SerializesModels::class) ->toHaveLineCountLessThan(100) ->not->toHaveSuffix('Event'); @@ -119,16 +130,25 @@ arch('Middleware') arch('Requests') ->expect('App\Http\Requests') ->toBeClasses() - ->toExtend('Illuminate\Foundation\Http\FormRequest') + ->toExtend(\Illuminate\Foundation\Http\FormRequest::class) ->toHaveMethod('rules') ->toOnlyBeUsedIn('App\Http\Controllers') ->toHaveLineCountLessThan(150) ->toHaveSuffix('Request'); +arch('Resources') + ->expect('App\Http\Resources') + ->toBeClasses() + ->toExtend(\Illuminate\Http\Resources\Json\JsonResource::class) + ->toOnlyBeUsedIn('App\Http\Controllers') + ->toHaveLineCountLessThan(150) + ->toHaveSuffix('Resource'); + arch('Jobs') ->expect('App\Jobs') ->toBeClasses() - ->toImplement('Illuminate\Contracts\Queue\ShouldQueue') + ->toImplement(\Illuminate\Contracts\Queue\ShouldQueue::class) + ->toUseTrait(\Illuminate\Foundation\Bus\Dispatchable::class) ->not->toHavePublicMethodsBesides(['handle']) ->toHaveLineCountLessThan(250) ->toHaveSuffix('Job'); @@ -142,22 +162,22 @@ arch('Listeners') arch('Mail') ->expect('App\Mail') ->toBeClasses() - ->toExtend('Illuminate\Mail\Mailable') - ->toImplement('Illuminate\Contracts\Queue\ShouldQueue') + ->toExtend(\Illuminate\Mail\Mailable::class) + ->toImplement(\Illuminate\Contracts\Queue\ShouldQueue::class) ->toHaveLineCountLessThan(150); arch('Models') ->expect('App\Models') ->toBeClasses() ->toOnlyUse('Illuminate\Database') - ->not->toUseTrait('Illuminate\Database\Eloquent\SoftDeletes') + ->not->toUseTrait(\Illuminate\Database\Eloquent\SoftDeletes::class) ->toHaveLineCountLessThan(250) ->not->toHaveSuffix('Model'); arch('Notifications') ->expect('App\Notifications') ->toBeClasses() - ->toExtend('Illuminate\Notifications\Notification') + ->toExtend(\Illuminate\Notifications\Notification::class) ->toHaveLineCountLessThan(150) ->not->toHaveSuffix('Notification'); @@ -171,20 +191,21 @@ arch('Providers') ->expect('App\Providers') ->toBeClasses() ->toHaveSuffix('ServiceProvider') - ->toExtend('Illuminate\Support\ServiceProvider') + ->toExtend(\Illuminate\Support\ServiceProvider::class) ->not->toBeUsed() ->toHaveLineCountLessThan(250); arch('Queries') ->expect('App\Queries') ->toBeClasses() - ->toExtend('Illuminate\Database\Eloquent\Builder') + ->toExtend(\Illuminate\Database\Eloquent\Builder::class) ->not->toHavePublicMethodsBesides(['__construct', 'builder']) ->toHaveLineCountLessThan(150); arch('Services') ->expect('App\Services') ->toBeClasses() + ->toHaveSuffix('Service') ->toHaveLineCountLessThan(250); arch('Traits')