anthonyedmonds / laravel-testing-traits
Make testing easier with this collection of testing traits!
Installs: 1 184
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.3
- laravel/framework: ^11
- phpunit/phpunit: ^11
README
Make testing easier with this collection of testing traits!
Installation
- Add the library using Composer:
composer require anthonyedmonds/laravel-testing-traits --dev
- The service provider will be automatically registered. If required, you can manually register the service provider by adding it to your bootstrap/providers.php:
return [ ... AnthonyEdmonds\GovukLaravel\Providers\GovukServiceProvider::class, ... ];
- If you are not using the standard
App\Models\User
model, publish the config file using Artisan:
Then update the config to point to your model:php artisan vendor:publish --provider="AnthonyEdmonds\LaravelTestingTraits\TestingTraitsServiceProvider"
return [ 'user_model' => \App\Models\User::class, ];
Usage
- Add the desired traits to your
Tests\TestCase.php
class - Use the test methods in your tests:
$this->assertFormRequestPasses(...); $this->assertBelongsTo(...);
Available traits
PHPUnit Extension
An extension is provided for asserting that all blade files in your project have been rendered successfully.
When used in conjunction with assertViewRenders
, an check will be performed at the end of all unit tests to ensure that all blade files within resources/views
have been rendered at least once.
<phpunit> <extensions> <bootstrap class="AnthonyEdmonds\LaravelTestingTraits\PhpUnit\AssertAllViewsRenderedExtension"/> </extensions> </phpunit>
The results are output into the terminal and recorded in .phpunit.cache/view-render-results.json
.