Installation:
composer require --dev dab-libs/waesel-bundle
Ensure the bundle is enabled in config/bundles.php (Symfony 5+).
First Use Case:
Fixture to define test data.WeaselTestCase (or manually bootstrapping the bundle).use DabLibs\WeaselBundle\Test\WeaselTestCase;
class FindPetsTest extends WeaselTestCase
{
protected function getFixtures(): array
{
return [new FindPets_Fixture($this->getService('create_pet'))];
}
public function testFindPetsByName()
{
$service = $this->getService('find_pets');
$pets = $service->do(null, 'cat');
$this->assertCount(2, $pets); // pet1 (cat) + pet2 (cat)
}
}
Key Files to Explore:
src/Test/WeaselTestCase.php (base test class).src/Fixture/FixtureInterface.php (fixture contract).src/WeaselBundle.php (bundle configuration).Fixture-Based Testing:
User_Fixture, Order_Fixture).getFixtures().protected function getFixtures(): array
{
return [
new User_Fixture($this->getService('user_repository')),
new Order_Fixture($this->getService('order_repository')),
];
}
Service Injection:
$this->getService('service_id') in tests.Test Lifecycle:
WeaselTestCase::setUp() to customize behavior (e.g., per-test fixture resets).Database Transactions:
DatabaseTestCase behavior).use DabLibs\WeaselBundle\Test\WeaselTestCase;
use PHPUnit\Framework\TestCase;
class HybridTest extends WeaselTestCase & TestCase { ... }
$this->createMock(ExternalApi::class);
public function createData(): void {
$this->pet1 = $this->createPet->do('pet_' . uniqid(), Pet::CAT);
}
Fixture Scope:
tearDown() if needed.protected function tearDown(): void
{
$this->getService('cache')->clear();
parent::tearDown();
}
Service Unavailability:
getService() fails, verify:
config/bundles.php.Database Constraints:
Legacy Symfony:
createData() for exceptions. Use try-catch to log errors:
public function createData(): void {
try {
$this->pet1 = $this->createPet->do('pet1', Pet::CAT);
} catch (\Exception $e) {
$this->fail('Fixture creation failed: ' . $e->getMessage());
}
}
php bin/console debug:container to verify service IDs.WeaselTestCase to add pre/post-fixture logic:
class CustomTestCase extends WeaselTestCase {
protected function loadFixtures(array $fixtures): void {
// Custom logic (e.g., parallel fixture loading)
parent::loadFixtures($fixtures);
}
}
weasel.fixture.load or weasel.fixture.create events (if the bundle supports them).// In phpunit.xml
<php>
<server name="WEASEL_PARALLEL" value="1"/>
</php>
How can I help you explore Laravel packages today?