matthiasnoback/phpunit-test-service-container
ServiceProvider pattern, enabling modular test configuration (e.g., DatabaseServiceProvider, CacheServiceProvider for tests).Container without conflicts.TestCase base class with built-in container access, reducing boilerplate for Laravel’s PHPUnit\Framework\TestCase.Illuminate namespace collisions).Mockery, createMock()), so test doubles must be manually configured.Mockery/createMock() or supplement it?DatabaseServiceProvider)?Testing facade (e.g., actingAs(), followRedirects())?Illuminate/Container.Feature\AuthTests) to evaluate fit.php artisan make:test-provider AuthServiceProvider).app()->make()).Illuminate\Foundation\Testing\TestCase with the package’s base class in phpunit.xml:
<testsuites>
<testsuite name="Application">
<directory>./tests</directory>
<baseClass>MatthiasNoback\TestServiceContainer\TestCase</baseClass>
</testsuite>
</testsuites>
AppServiceProvider test overrides into dedicated test providers (e.g., AuthServiceProviderTest).laravel/breeze) won’t break, but test-specific overrides may require manual handling.createTestUser()) can be reused by injecting them into the test container.composer require matthiasnoback/phpunit-test-service-container.tests/TestServiceContainer.php).tests/Providers/DatabaseTestProvider.php).use MatthiasNoback\TestServiceContainer\ServiceProvider;
use MatthiasNoback\TestServiceContainer\Container;
class DatabaseTestProvider extends ServiceProvider {
public function register(Container $container) {
$container->set('db.connection', fn() => new FakeConnection());
}
}
use MatthiasNoback\TestServiceContainer\TestCase;
class UserTest extends TestCase {
protected function getServiceProviders() {
return [DatabaseTestProvider::class];
}
}
league/container).$this->container->debug() to inspect test services.set('service', fn() => new HeavyService())) to defer instantiation.How can I help you explore Laravel packages today?