illuminate/testing
Laravel’s Illuminate Testing package provides the core testing helpers used by the framework—HTTP and console test utilities, assertions, test case scaffolding, and support traits—making it easier to write fast, expressive PHPUnit tests for Laravel applications and packages.
Start by installing the package via Composer: composer require --dev illuminate/testing. This package contains core testing abstractions used by Laravel applications—particularly TestCase, ConsoleTestTrait, and DatabaseTestTrait. If you're building a Laravel app, you typically don't install this directly; it's pulled in via laravel/framework. But if you're authoring a package that needs Laravel's test utilities (e.g., custom Artisan commands, Eloquent-based libraries), this is the standalone entry point. First file to inspect is TestCase.php, which provides the base test class with helper methods like assertDatabaseCount() and actingAs(). Run your first test with phpunit tests/Feature/ExampleTest.php.
illuminate/testing\TestCase as your test base class instead of PHPUnit’s directly—it integrates Laravel’s service container, facades, and database tooling.RefreshDatabase (reduces DB setup/teardown overhead) and WithFaker for data generation.$this->mock(Contract::class) or $this->spy()—methods exposed in the base TestCase.Artisan::call() within tests via Tests\TestCase to execute console commands deterministically; combine with expectsOutput() and assertExitCode().Bus::fake() to assert dispatching without side effects, and Bus::assertDispatched() for verification.TestResponse helpers like assertJson() and assertStatus()—these are shared with Laravel’s test utilities.illuminate/testing version matches other illuminate/* packages—mismatches (e.g., 12.x vs 13.x) cause cryptic resolution errors or missing methods.laravel/framework repo.$this->app->instance(...)) without cleaning up, other tests may leak state. Prefer refreshApplication() in setUp() or RefreshDatabase for DB resets.RefreshDatabase is slower than DatabaseTransactions; use the latter for unit tests that don’t require database persistence (via UsesDatabaseTransactions trait).WithFaker, avoid calling Faker::create() manually—stick to $this->faker to prevent seeding inconsistency.TestCase with custom assertions (e.g., assertQueuePushed($job, $payload)) by adding traits or methods to your app’s tests/TestCase.php.How can I help you explore Laravel packages today?