Installation:
composer require blast-project/tests-bundle
Add the bundle to your config/bundles.php:
return [
// ...
Blast\TestsBundle\TestsBundle::class => ['test' => true],
];
First Test Class:
Extend BlastTestCase in your test file (located in tests/Functional/ or similar):
use Blast\TestsBundle\Functional\BlastTestCase;
class MyServiceTest extends BlastTestCase
{
public function testServiceInitialization()
{
$this->isServicesAreInitializable('blast'); // Checks if services prefixed with 'blast' are loadable
}
}
Run Tests:
php bin/phpunit
blast.*) are autowired and functional.KernelTestCase for HTTP/container testing with Blast-specific shortcuts.Service Initialization Checks:
Use isServicesAreInitializable() to validate service autowiring for a given prefix (e.g., blast.*).
$this->isServicesAreInitializable('blast', ['blast.command.*']); // Exclude specific services
HTTP Test Integration:
Combine with Symfony’s Client for API testing:
public function testApiEndpoint()
{
$client = static::createClient();
$response = $client->request('GET', '/api/endpoint');
$this->assertEquals(200, $response->getStatusCode());
}
Database Transactions:
Override setUp() to enable transactions:
protected function setUp(): void
{
parent::setUp();
$this->enableTransactions();
}
Custom Assertions:
Extend BlastTestCase to add domain-specific assertions:
protected function assertServiceHasMethod($serviceId, $method)
{
$service = $this->getService($serviceId);
$this->assertTrue(method_exists($service, $method));
}
$this->getService('blast.service') (wrapped by the bundle).static::getContainer()->getParameter('blast.config') to validate config values.$this->getService('event_dispatcher')->dispatch(new BlastEvent());
Service Prefix Mismatch:
isServicesAreInitializable() defaults to blast.*. Explicitly pass the correct prefix:
$this->isServicesAreInitializable('app.*'); // Not 'blast.*'
['prefix' => 'custom.'] as the second argument.Transaction Isolation:
enableTransactions() rolls back after each test. For multi-test scenarios, disable it:
$this->disableTransactions();
Kernel Caching:
$this->getKernel()->getContainer()->get('kernel')->clearContainer();
Missing Readme:
src/Functional/BlastTestCase.php for undocumented methods.$this->dumpServices(); // Lists all services (debug:dump-service)
$this->dumpContainerParameters();
Custom Assertions:
Override BlastTestCase to add methods like:
protected function assertBlastConfigValid()
{
$config = $this->getParameter('blast.config');
$this->assertArrayHasKey('required_key', $config);
}
Pre-Test Hooks:
Extend setUp() to inject test data:
protected function setUp(): void
{
parent::setUp();
$this->loadFixtures([__DIR__.'/fixtures/blast.yml']);
}
Post-Test Cleanup:
Override tearDown() to reset state:
protected function tearDown(): void
{
$this->clearDatabase(); // Hypothetical method
parent::tearDown();
}
isServicesAreInitializable()).composer.json constraints.How can I help you explore Laravel packages today?