endeavour-agency / refresh-database-on-demand
This packages offers a drop-in replacement for Laravel's RefreshDatabase trait, which only refreshes the database when migrations have actually changed.
Requires
- php: ^8.2
- laravel/framework: ^11
Requires (Dev)
- orchestra/testbench: ^9
- phpunit/phpunit: ^11
This package is auto-updated.
Last update: 2025-02-23 14:29:13 UTC
README
This package offers a drop-in replacement for Laravel's RefreshDatabase trait.
Laravel's default RefreshDatabase
trait always performs a migrate:fresh
at the start of running a single or multiple tests, even when migrations haven't been added or deleted.
When using this package's RefreshDatabaseOnDemand
trait instead, migrate:fresh
will only be called when new migrations have been added or migrations have been deleted. This significantly reduces start-up time of running a single or a set of tests.
Installation
To install the package, simply require it with composer:
composer require endeavour-agency/refresh-database-on-demand
Usage
To start using the power of on-demand database refreshing, replace any occurrence of Illuminate\Foundation\Testing\RefreshDatabase
with EndeavourAgency\RefreshDatabaseOnDemand\Traits\RefreshDatabaseOnDemand
.
Before:
<?php namespace Tests\Unit; use Illuminate\Foundation\Testing\RefreshDatabase; use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\Test; class ExampleTest extends TestCase { use RefreshDatabase; ... }
After:
<?php namespace Tests\Unit; use EndeavourAgency\RefreshDatabaseOnDemand\Traits\RefreshDatabaseOnDemand; use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\Test; class ExampleTest extends TestCase { use RefreshDatabaseOnDemand; ... }