test: improve ArchTest

- add more rules for the entire app
- add Resources rule
- improve existing rules
- adjust formatting
This commit is contained in:
peaklabs-dev 2025-04-22 22:06:20 +02:00
parent b2406eedb0
commit 3f9f400c75
No known key found for this signature in database

View file

@ -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')