spiral/testing
Testing SDK for Spiral Framework packages. Provides a custom TestCase with a TestApp so you can test packages without a full application setup. Configure root directory and bootloaders, and keep test app config under tests/app. PHP 8.1+, Spiral 3.15+.
Begin by installing the package via Composer: composer require --dev spiral/testing. Then create your first test by extending Spiral\Tests\FrameworkTestCase (or KernelTestCase depending on version), which automatically bootstraps the Spiral kernel and injects a ready-to-use container. Your first use case will likely be testing a service class: call $this->get(ContainerInterface::class)->get(MyService::class) and assert behavior—no manual app bootstrap needed.
self::bootKernel() to load the full container and resolve dependencies via $this->get(Service::class). Ideal for unit/integration hybrid tests where wiring matters.$this->getRouteTester() (if available in version) or manually dispatch requests through the kernel with $this->kernel->handle($request), verifying responses and side effects.spiral/database-test.php) and use self::withTransaction() to wrap test methods in a transaction that rolls back automatically.setUp() and rely on tearDown()—the framework provides base implementations that clear caches, reset containers, and reset static state.$this->mock(SomeInterface::class, $overrides) to safely override bindings in the container for test-specific behavior without affecting other tests.tearDown(), remember to clear global singletons (e.g., static caches in services like Config or Logger) manually if they’re not registered as Scopes::SINGLETON—check service definitions for SingletonInterface.self::overrideConfig() in tests to inject test-specific config (e.g., database.connection = 'test') without modifying real config files. Always scope overrides to the current test context.bootKernel() multiple times in one test method—bootstrap once in setUp() or via before() (pest) to prevent container conflicts.$this->bind(SomeInterface::class, $mock) over $this->mock() when you need to replace a non-singleton shared dependency across multiple instantiations.phpspiral test:clean (if CLI tool exists) to clear precompiled caches—this package caches bootsrap artifacts to speed up repeated test runs, but stale caches can cause subtle failures after refactors.How can I help you explore Laravel packages today?