test: improve arch test

- add attribute test
- order all test cases and their assertions
- remove unused test case
This commit is contained in:
peaklabs-dev 2025-12-01 18:09:56 +01:00
parent 1582320651
commit 93cc12a308
No known key found for this signature in database

View file

@ -14,12 +14,14 @@ arch('App')
->expect('App')
->not->toBeEnums()
->ignoring('App\Enums')
->not->toImplement(Throwable::class)
->ignoring('App\Exceptions')
->not->toExtend(\Illuminate\Database\Eloquent\Model::class)
->ignoring('App\Models')
->not->toExtend(\Illuminate\Foundation\Http\FormRequest::class)
->ignoring('App\Http\Requests')
->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->toExtend(\Illuminate\Console\Command::class)
->ignoring('App\Console\Commands')
->not->toExtend(\Illuminate\Mail\Mailable::class)
@ -28,29 +30,33 @@ arch('App')
->ignoring('App\Notifications')
->not->toExtend(\Illuminate\Support\ServiceProvider::class)
->ignoring('App\Providers')
->not->toHaveSuffix('ServiceProvider')
->ignoring('App\Providers')
->not->toHaveSuffix('Controller')
->ignoring('App\Http\Controllers')
->not->toImplement(Throwable::class)
->ignoring('App\Exceptions')
->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');
->ignoring('App\Events')
->not->toHaveSuffix('Controller')
->ignoring('App\Http\Controllers')
->not->toHaveSuffix('ServiceProvider')
->ignoring('App\Providers');
arch('Actions')
->expect('App\Actions')
->toBeClasses()
arch('Contracts')
->expect('App\Contracts')
->toBeInterfaces()
->toExtendNothing()
->toImplementNothing()
->not->toHavePublicMethodsBesides(['handle'])
->toHaveLineCountLessThan(250)
->toHaveSuffix('Action');
->toHaveLineCountLessThan(100);
arch('Attributes')
->expect('App\Attributes')
->toBeClasses()
->toHaveMethod(method: 'resolve')
->toHaveAttribute('Attribute')
->toImplement(\Illuminate\Contracts\Container\ContextualAttribute::class)
->toHaveLineCountLessThan(100);
arch('Concerns')
->expect('App\Concerns')
@ -60,21 +66,13 @@ arch('Concerns')
->toHaveLineCountLessThan(100)
->toHavePrefix('Has');
arch('Commands')
->expect('App\Console\Commands')
->toBeClasses()
->toExtend(\Illuminate\Console\Command::class)
->toImplementNothing()
->not->toHavePublicMethodsBesides(['handle'])
->toHaveLineCountLessThan(150)
->toHaveSuffix('Command');
arch('Contracts')
->expect('App\Contracts')
->toBeInterfaces()
arch('Traits')
->expect('App\Traits')
->toBeTraits()
->toExtendNothing()
->toImplementNothing()
->toHaveLineCountLessThan(100);
->toHaveLineCountLessThan(100)
->toHavePrefix('Has');
arch('Enums')
->expect('App\Enums')
@ -84,21 +82,6 @@ arch('Enums')
->toImplementNothing()
->toHaveLineCountLessThan(80);
arch('Features')
->expect('App\Features')
->toBeClasses()
->ignoring('App\Features\Concerns')
->toHaveMethod('resolve')
->toHaveLineCountLessThan(250);
arch('Events')
->expect('App\Events')
->toBeClasses()
->toExtendNothing()
->toUseTrait(\Illuminate\Queue\SerializesModels::class)
->toHaveLineCountLessThan(100)
->not->toHaveSuffix('Event');
arch('Exceptions')
->expect('App\Exceptions')
->toBeClasses()
@ -112,6 +95,12 @@ arch('Http')
->toBeClasses()
->toOnlyBeUsedIn('App\Http');
arch('Middleware')
->expect('App\Http\Middleware')
->toBeClasses()
->toHaveMethod('handle')
->toHaveLineCountLessThan(150);
arch('Controllers')
->expect('App\Http\Controllers')
->toBeClasses()
@ -121,17 +110,11 @@ arch('Controllers')
->ignoring('App\Http\Controllers\Api')
->toHaveSuffix('Controller');
arch('Middleware')
->expect('App\Http\Middleware')
->toBeClasses()
->not->toHavePublicMethodsBesides(['handle'])
->toHaveLineCountLessThan(150);
arch('Requests')
->expect('App\Http\Requests')
->toBeClasses()
->toHaveMethod(method: 'rules')
->toExtend(\Illuminate\Foundation\Http\FormRequest::class)
->toHaveMethod('rules')
->toOnlyBeUsedIn('App\Http\Controllers')
->toHaveLineCountLessThan(150)
->toHaveSuffix('Request');
@ -144,20 +127,52 @@ arch('Resources')
->toHaveLineCountLessThan(150)
->toHaveSuffix('Resource');
arch('Jobs')
->expect('App\Jobs')
arch('Actions')
->expect('App\Actions')
->toBeClasses()
->toImplement(\Illuminate\Contracts\Queue\ShouldQueue::class)
->toUseTrait(\Illuminate\Foundation\Bus\Dispatchable::class)
->not->toHavePublicMethodsBesides(['handle'])
->toExtendNothing()
->toImplementNothing()
->toHaveLineCountLessThan(250)
->toHaveSuffix('Job');
->not->toHaveSuffix('Action');
arch('Services')
->expect('App\Services')
->toBeClasses()
->toHaveLineCountLessThan(250)
->toHaveSuffix('Service');
arch('Events')
->expect('App\Events')
->toBeClasses()
->toExtendNothing()
->toUseTrait(\Illuminate\Queue\SerializesModels::class)
->toHaveLineCountLessThan(100)
->not->toHaveSuffix('Event');
arch('Listeners')
->expect('App\Listeners')
->toBeClasses()
->not->toHavePublicMethodsBesides(['__construct', 'handle'])
->toHaveLineCountLessThan(150);
->toHaveLineCountLessThan(100);
arch('Commands')
->expect('App\Console\Commands')
->toBeClasses()
->not->toHavePublicMethodsBesides(['handle'])
->toExtend(\Illuminate\Console\Command::class)
->toImplementNothing()
->toHaveLineCountLessThan(150)
->toHaveSuffix('Command');
arch('Jobs')
->expect('App\Jobs')
->toBeClasses()
->not->toHavePublicMethodsBesides(['handle'])
->toImplement(\Illuminate\Contracts\Queue\ShouldQueue::class)
->toUseTrait(\Illuminate\Foundation\Bus\Dispatchable::class)
->toHaveLineCountLessThan(250)
->toHaveSuffix('Job');
arch('Mail')
->expect('App\Mail')
@ -166,20 +181,28 @@ arch('Mail')
->toImplement(\Illuminate\Contracts\Queue\ShouldQueue::class)
->toHaveLineCountLessThan(150);
arch('Models')
->expect('App\Models')
->toBeClasses()
->toOnlyUse('Illuminate\Database')
->not->toUseTrait(\Illuminate\Database\Eloquent\SoftDeletes::class)
->toHaveLineCountLessThan(250)
->not->toHaveSuffix('Model');
arch('Notifications')
->expect('App\Notifications')
->toBeClasses()
->toExtend(\Illuminate\Notifications\Notification::class)
->toHaveLineCountLessThan(150)
->not->toHaveSuffix('Notification');
->toHaveLineCountLessThan(200)
->toHaveSuffix('Notification');
arch('Models')
->expect('App\Models')
->toBeClasses()
->toExtend(\Illuminate\Database\Eloquent\Model::class)
->not->toUseTrait(\Illuminate\Database\Eloquent\SoftDeletes::class)
->toOnlyUse('Illuminate\Database')
->toHaveLineCountLessThan(250)
->not->toHaveSuffix('Model');
arch('Queries')
->expect('App\Queries')
->toBeClasses()
->toExtend(\Illuminate\Database\Eloquent\Builder::class)
->not->toHavePublicMethodsBesides(['__construct', 'builder'])
->toHaveLineCountLessThan(150);
arch('Policies')
->expect('App\Policies')
@ -190,31 +213,11 @@ arch('Policies')
arch('Providers')
->expect('App\Providers')
->toBeClasses()
->toHaveSuffix('ServiceProvider')
->toExtend(\Illuminate\Support\ServiceProvider::class)
->not->toBeUsed()
->toHaveLineCountLessThan(250);
arch('Queries')
->expect('App\Queries')
->toBeClasses()
->toExtend(\Illuminate\Database\Eloquent\Builder::class)
->not->toHavePublicMethodsBesides(['__construct', 'builder'])
->toHaveLineCountLessThan(150);
arch('Services')
->expect('App\Services')
->toBeClasses()
->toHaveSuffix('Service')
->toHaveLineCountLessThan(250);
arch('Traits')
->expect('App\Traits')
->toBeTraits()
->toExtendNothing()
->toImplementNothing()
->toHaveLineCountLessThan(100);
->toHaveLineCountLessThan(250)
->toHaveSuffix('ServiceProvider');
arch('Functions')
->expect(['dd', 'ddd', 'dump', 'env', 'exit'])
->expect(['dd', 'ddd', 'dump', 'env', 'exit', 'ray'])
->not->toBeUsed();