Installation:
composer require-dev atoum/atoum-bundle
Add to config/bundles.php (Symfony 7+):
atoum\AtoumBundle\AtoumAtoumBundle::class => ['dev' => true, 'test' => true],
First Test:
Create a test class extending atoum\AtoumBundle\Test\Units\Test:
// tests/Unit/MyTest.php
namespace Tests\Unit;
use atoum\AtoumBundle\Test\Units\Test;
class MyTest extends Test {
public function testExample() {
$this->boolean(true)->isTrue();
}
}
Run Tests:
php bin/console atoum --directory=tests/Unit
Test for simple assertions.WebTestCase for HTTP requests.CommandTestCase for CLI commands.FormTestCase for Symfony forms.Base Classes:
Test: For unit tests (e.g., services, entities).WebTestCase: For HTTP/Controller tests (extends Test).CommandTestCase: For Symfony commands.FormTestCase: For Symfony forms.Example Workflow:
// tests/Unit/Service/MyServiceTest.php
class MyServiceTest extends Test {
public function testServiceMethod() {
$service = $this->getService('my_service');
$result = $service->doSomething();
$this->string($result)->isEqualTo('expected');
}
}
config/packages/test/atoum.yaml:
atoum:
bundles:
AppBundle:
directories: [Tests/Unit, Tests/Functional]
php bin/console atoum AppBundle
public function testWithFakeData() {
$fakeName = $this->faker->name;
$this->string($fakeName)->isNotEmpty();
}
class MyControllerTest extends ControllerTest {
public function testGetAction() {
$this->request()->GET('/endpoint')->hasStatus(200);
}
}
getKernelDirectory() if Symfony can't auto-detect:
class MyWebTest extends WebTestCase {
protected function getKernelDirectory() {
return __DIR__ . '/../../../../var/cache/dev';
}
}
CommandTestCase:
class MyCommandTest extends CommandTestCase {
public function testExecute() {
$command = new MyCommand();
$commandTester = $this->createCommandTester($command);
$exitCode = $commandTester->execute([]);
$this->integer($exitCode)->isEqualTo(0);
}
}
php bin/console atoum --directory=tests --report=xunit
Kernel Initialization Issues:
No kernel found or AppKernel not found.getKernelDirectory() in your test class or ensure APP_KERNEL_DIR is set in .env.test.Directory Configuration:
--directory flag for Symfony 7+:
php bin/console atoum --directory=tests/Unit --directory=tests/Integration
Faker Not Available:
$this->faker throws UndefinedPropertyException.fakerphp/faker is installed (composer require-dev fakerphp/faker).Exit Codes:
--debug to inspect underlying atoum output:
php bin/console atoum --debug
php bin/console atoum --verbose
php bin/console atoum --light-report
php bin/console atoum --loop
Custom Test Classes: Extend base classes to add pre/post hooks:
class CustomTest extends Test {
protected function beforeTestMethod($method) {
$this->mock('service')->get('mocked');
}
}
Atoum Configuration: Pass atoum-specific options via CLI:
php bin/console atoum --directory=tests --filter="testMethod"
Symfony Services:
Access services in tests via $this->getService('service_id').
AcmeFooBundle) in atoum.yaml, not aliases.composer.json enforces PHP 8.1+ for AtoumBundle 3.0+.composer.json autoloads correctly.@noResetKernel annotation for fast unit tests:
/**
* @noResetKernel
*/
class FastUnitTest extends Test { ... }
parallel-lint or custom scripts.composer.json:
"autoload": {
"psr-4": { "Tests\\": "tests/" }
}
ContainerAwareCommand with dependency-injected Command.
How can I help you explore Laravel packages today?