atoum-next / atoum-bundle
Bundle around atoum unit testing framework
Package info
github.com/AtoumNext/AtoumBundle
Type:symfony-bundle
pkg:composer/atoum-next/atoum-bundle
Requires
- php: >=8.2
- ext-dom: *
- atoum-next/atoum: ^5.0.1
- fakerphp/faker: ^1.23
- symfony/console: ^7.4 || ^8.0
- symfony/css-selector: ^7.4 || ^8.0
- symfony/dom-crawler: ^7.4 || ^8.0
- symfony/finder: ^7.4 || ^8.0
- symfony/framework-bundle: ^7.4 || ^8.0
Requires (Dev)
- atoum/stubs: ^2.6
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^2.1
- phpstan/phpstan-symfony: ^2.0
- rector/rector: ^2.0
- symfony/form: ^7.4 || ^8.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master / 5.x-dev
- v5.1.0
- v5.0.1
- v5.0.0
- 3.0.0
- 2.0.0
- 1.6.0
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.0
- v0
- dev-fix/symfony-flex-projects
- dev-fix/require-atoum-next-5.0.1
- dev-feature/atoum-next-v5
- dev-fix-env-matrix
- dev-php-doc
- dev-atoum-default-bootstrap
- dev-loop-mode
- dev-fix-tests
- dev-custom-test-env
This package is auto-updated.
Last update: 2026-11-29 18:47:57 UTC
README
This bundle provides a (very) simple integration of atoum, the simple, modern and intuitive unit testing framework for PHP, into Symfony.
Version 5.0+ requires Symfony 7.4 or 8.0+ and PHP 8.2+, and runs on atoum-next/atoum.
Installation
With composer
composer require --dev atoum-next/atoum-bundle
Note: For Symfony 6 and earlier versions, use the former atoum/atoum-bundle package (^2.0).
The Symfony Flex recipe is not published yet: register the bundle (below) and copy
recipes/atoum-next/atoum-bundle/5.0/.atoum.php
to your project root.
Command
AtoumBundle is provided with a Symfony command. You can launch atoum tests on specific bundles.
Registering in the kernel
Add AtoumBundle to your config/bundles.php (Symfony 4+):
return [ // ... atoum\AtoumBundle\AtoumAtoumBundle::class => ['dev' => true, 'test' => true], ];
For older Symfony versions, add to your AppKernel.php:
if (in_array($this->getEnvironment(), array('dev', 'test'))) { //..... $bundles[] = new atoum\AtoumBundle\AtoumAtoumBundle(); }
Configuration
Define your bundles in config/packages/test/atoum.yaml:
atoum: bundles: # note that the full name, including vendor, is required AcmeFooBundle: ~ # FooBundle is defined with directories Tests/Units, Tests/Controller MeBarBundle: directories: [Tests/Units, Tests/Functional, ...]
For Symfony 3 and earlier, use config_test.yml instead.
Command-line usage
Modern Symfony 7+ approach (recommended):
# Test any directory directly (no configuration needed!)
$ php bin/console atoum --directory=src/Tests
$ php bin/console atoum --directory=tests
$ php bin/console atoum --directory=tests/Unit --directory=tests/Integration --no-code-coverage
The command runs the tests in the test environment (APP_ENV=test) and, unless
--bootstrap-file says otherwise, bootstraps them with tests/bootstrap.php when the
project has one (it loads the .env files), vendor/autoload.php otherwise.
You can also run vendor/bin/atoum, which reads .atoum.php at the project root.
Legacy bundle-based approach (still supported):
$ php bin/console atoum FooBundle # launch tests of FooBundle $ php bin/console atoum FooBundle BarBundle # launch tests of FooBundle and BarBundle $ php bin/console atoum acme_foo # launch tests of bundle where alias is acme_foo $ php bin/console atoum # launch tests from configuration
Simple Usage
Make your test class extend the atoum\AtoumBundle\Test\Units\Test class of the bundle.
Don't forget to load this class with your favorite method (require, autoload, ...) if you don't use composer.
<?php // src/Acme/MyBundle/Tests/Units/Entity/HelloWorld.php namespace Acme\MyBundle\Tests\Units\Entity; // if you don't use a bootstrap file, (or composer) you need to require the application autoload //require __DIR__ . '/../../../../../../app/autoload.php'; // use path of the atoum.phar as bellow if you don't want to use atoum via composer //require_once __DIR__ . '/../../../../../vendor/atoum.phar'; use atoum\AtoumBundle\Test\Units; class helloWorld extends Units\Test { }
Web test case
You can easily create a kernel environment:
<?php use atoum\AtoumBundle\Test\Units; class helloWorld extends Units\WebTestCase { public function testMyTralala() { $client = $this->createClient(); } }
Command test case
You can also easily test a command:
<?php namespace My\Bundle\FoobarBundle\Tests\Units\Command; use atoum\AtoumBundle\Test\Units as AtoumBundle; use atoum\atoum; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; // Assuming that this command will display "Success" if succes, and returns a boolean use My\Bundle\FoobarBundle\Command\FoobarCommand as Base; class FoobarCommand extends AtoumBundle\CommandTestCase { public function testExecute() { $this ->given( $command = new Base() ) ->if($commandTester = $this->createCommandTester($command)) ->then ->boolean($commandTester->execute()) ->isTrue() ->string($commandTester->getDisplay()) ->contains("Success") ; } }
Which kernel is booted
WebTestCase and CommandTestCase boot, in this order:
- the class named by the
KERNEL_CLASSenvironment variable (Symfony Flex projects define it in.env.test); App\Kernel;- the
*Kernel.phpfile found in theapp/directory (Symfony 3 layout): overridegetKernelDirectoryto point elsewhere, orcreateKernelto build the kernel yourself.
Test a controller
You can test your controller with the ControllerTest class (it extends WebTestCase - each file must correspond to a Symfony2 controller):
<?php namespace vendor\FooBundle\Tests\Controller; use atoum\AtoumBundle\Test\Units\WebTestCase; use atoum\AtoumBundle\Test\Controller\ControllerTest; class BarController extends ControllerTest { public function testGet() { $this ->request(array('debug' => true)) ->GET('/demo/' . uniqid()) ->hasStatus(404) ->hasCharset('UTF-8') ->hasVersion('1.1') ->POST('/demo/contact') ->hasStatus(200) ->hasHeader('Content-Type', 'text/html; charset=UTF-8') ->crawler ->hasElement('#contact_form') ->hasChild('input')->exactly(3)->end() ->hasChild('input') ->withAttribute('type', 'email') ->withAttribute('name', 'contact[email]') ->end() ->hasChild('input[type=submit]') ->withAttribute('value', 'Send') ->end() ->hasChild('textarea')->end() ->end() ->hasElement('li') ->withContent('The CSRF token is invalid. Please try to resubmit the form.') ->exactly(1) ->end() ->hasElement('title') ->hasNoChild() ->end() ->hasElement('meta') ->hasNoContent() ->end() ->hasElement('link') ->isEmpty() ->end() ; } }
Test a form type
You can test your form types with the FormTestCase class as the official symfony 2 documentation shows it.
But as the official documentation fits the PHPUnit testing framework, here comes this documentation
first example atoum-translated :
<?php namespace Acme\DemoBundle\Tests\Form; use Acme\DemoBundle\Entity\TestEntity; use atoum\AtoumBundle\Test\Form; use Acme\DemoBundle\Form\TestEntityType as MyTypeToTest; class TestEntityType extends Form\FormTestCase{ public function testToutCourt() { $formData = array( 'texte1' => 'test 1', 'texte2' => 'test 2', ); $type = new MyTypeToTest(); $form = $this->factory->create($type); $object = new TestEntity(); $object->fromArray($formData); // submit the data to the form directly $form->submit($formData); $this->boolean($form->isSynchronized())->isTrue(); $this->variable($object)->isEqualTo($form->getData()); $view = $form->createView(); $children = $view->children; foreach (array_keys($formData) as $key) { $this->array($formData)->hasKey($key); } } }
Faker data
AtoumBundle integrates with Faker library.
In your tests classes, you have access to a Faker\Generator instance with the faker asserter.
public function testMyAmazingFeature() { //..... $randomName = $this->faker->name; $dateTimeBetweenYesterdayAndNow = $this->faker->dateTimeBetween('-1 day', 'now'); //..... }
See Faker's documentation about its usage.