anthonyedmonds/laravel-testing-traits

Make testing easier with this collection of testing traits!

0.7.7 2025-01-29 08:50 UTC

This package is auto-updated.

Last update: 2025-01-29 08:50:59 UTC


README

Make testing easier with this collection of testing traits!

Installation

  1. Add the library using Composer:
    composer require anthonyedmonds/laravel-testing-traits --dev
  2. 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,
        ...
    ];
  3. If you are not using the standard App\Models\User model, publish the config file using Artisan:
    php artisan vendor:publish --provider="AnthonyEdmonds\LaravelTestingTraits\TestingTraitsServiceProvider"
    
    Then update the config to point to your model:
    return [
        'user_model' => \App\Models\User::class,
    ];

Usage

  1. Add the desired traits to your Tests\TestCase.php class
  2. 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.