Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Testing Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Use illuminate/testing\TestCase as your test base class instead of PHPUnit’s directly—it integrates Laravel’s service container, facades, and database tooling.
  • Leverage traits like RefreshDatabase (reduces DB setup/teardown overhead) and WithFaker for data generation.
  • For package development, mock internal contracts using $this->mock(Contract::class) or $this->spy()—methods exposed in the base TestCase.
  • Use Artisan::call() within tests via Tests\TestCase to execute console commands deterministically; combine with expectsOutput() and assertExitCode().
  • When testing jobs, use Bus::fake() to assert dispatching without side effects, and Bus::assertDispatched() for verification.
  • For HTTP tests, use TestResponse helpers like assertJson() and assertStatus()—these are shared with Laravel’s test utilities.

Gotchas and Tips

  • Version lock: Ensure illuminate/testing version matches other illuminate/* packages—mismatches (e.g., 12.x vs 13.x) cause cryptic resolution errors or missing methods.
  • Subtree split limitation: As a read-only subtree split, no PRs or issues go here directly—report bugs in the main laravel/framework repo.
  • Container conflicts: If you override the app container in a test ($this->app->instance(...)) without cleaning up, other tests may leak state. Prefer refreshApplication() in setUp() or RefreshDatabase for DB resets.
  • Performance tip: RefreshDatabase is slower than DatabaseTransactions; use the latter for unit tests that don’t require database persistence (via UsesDatabaseTransactions trait).
  • Faker reset: If using WithFaker, avoid calling Faker::create() manually—stick to $this->faker to prevent seeding inconsistency.
  • Extensibility: You can extend TestCase with custom assertions (e.g., assertQueuePushed($job, $payload)) by adding traits or methods to your app’s tests/TestCase.php.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport