Skip to content
This bundle provides a simple integration of atoum into Symfony 2.
Find file
Latest commit 069b0bb @FlorianLB FlorianLB release version 1.3.0
Failed to load latest commit information.
Command add option xunit report file
Configuration Define Configuration by Bundle.
DomCrawler CS Fix & PHPDoc
Resources/config/services Define Configuration by Bundle.
Test fix compatibility with atoum 2.4.0
atoum Adds the ability to test Symfony commands
tests Adds the ability to test Symfony commands
.atoum.php Fix travis build since --test-all is deprecated
.gitignore Ignore .DS_Store file
.travis.yml switch to new travis infrastrucure
AtoumAtoumBundle.php Define Configuration by Bundle. release version 1.3.0
LICENCE First commit, copy of JediAtoumBundle, change namespace Add readme section about CommandTestCase


Build Status

This bundle provides a (very) simple integration of atoum, the simple, modern and intuitive unit testing framework for PHP, from mageekguy into Symfony2.


1 - With composer

    "require": {
        "atoum/atoum-bundle": "~1.1"

In most of the cases you don't need AtoumBundle in your production environment.

    "require-dev": {
        "atoum/atoum-bundle": "~1.1"

2 - Command

AtoumBundle is provided with a Symfony command. You can launch atoum tests on specific bundles.

2-a Registering in the kernel

You have to define AtoumBundle on AppKernel

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
    $bundles[] = new atoum\AtoumBundle\AtoumAtoumBundle();

2-b Configuration

Define your bundles on configuration (if you want to use it only in test environment, in config_test.yml only):

        # note that the full name, including vendor, is required
        AcmeFooBundle: ~ # FooBundle is defined with directories Tests/Units, Tests/Controller
            directories: [Tests/Units, Tests/Functional, ...]

2-c Command-line usage

Then you can use:

$ php app/console atoum FooBundle --env=test # launch tests of FooBundle
$ php app/console atoum FooBundle BarBundle --env=test # launch tests of FooBundle and BarBundle
$ php app/console atoum acme_foo --env=test # launch tests of bundle where alias is acme_foo
$ php app/console atoum --env=test # 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.


// 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/mageekguy.atoum.phar';

use atoum\AtoumBundle\Test\Units;

class helloWorld extends Units\Test

Web test case

You can easily create a kernel environment:


require __DIR__ . '/../../../../../../../app/autoload.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:


namespace My\Bundle\FoobarBundle\Tests\Units\Command;

use atoum\AtoumBundle\Test\Units as AtoumBundle;
use mageekguy\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\Tests\Units\Command\FoobarCommand as Base;

class FoobarCommand extends AtoumBundle\CommandTestCase
    public function testExecute()
                $command = new Base()
            ->if($commandTester = $this->createCommandTester($command))

Known issues

  • The path of the AppKernel cannot be found, override the method getKernelDirectory and add the path to your app directory.

Test a controller

You can test your controller with the ControllerTest class (it extends WebTestCase - each file must correspond to a Symfony2 controller):


namespace vendor\FooBundle\Tests\Controller;

use atoum\AtoumBundle\Test\Units\WebTestCase;
use atoum\AtoumBundle\Test\Controller\ControllerTest;

class BarController extends ControllerTest
    public function testGet()
            ->request(array('debug' => true))
                ->GET('/demo/' . uniqid())
                    ->hasHeader('Content-Type', 'text/html; charset=UTF-8')
                                ->withAttribute('type', 'email')
                                ->withAttribute('name', 'contact[email]')
                                ->withAttribute('value', 'Send')
                            ->withContent('The CSRF token is invalid. Please try to resubmit the form.')

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 :


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();

        // submit the data to the form directly


        $view = $form->createView();
        $children = $view->children;

        foreach (array_keys($formData) as $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.

Something went wrong with that request. Please try again.