FlorianLB / JediAtoumBundle

This bundle provides a (very) simple integration of Atoum into Symfony 2.
MIT License
2 stars 0 forks source link

/!\ This bundle is now deprecated, use atoum/AtoumBundle instead /!\


This bundle provides a (very) simple integration of Atoum, the unit testing framework, from mageekguy into Symfony2.

Installation

All with composer

{
    "require": {
        "jedi/atoum-bundle": "dev-master",
        "mageekguy/atoum": "dev-master"
    },
    "config": {
        "bin-dir": "bin"
    }
}

Composer & Atoum Phar

{
    "require": {
        "jedi/atoum-bundle": "dev-master"
    }
}

Download the Atoum PHAR archive.

Simple Usage

Make your test class extends the Tests\Units\Test class of the bundle.

Don't forget to load this class with your favorite method (require, autoload, ...)

<?php

//if you don't use a bootstrap file, you need to require the autoload
require __DIR__ . '/../../../../../../../vendor/autoload.php';

// use path of the atoum.phar as bello if you don't want to use atoum via composer
//require_once __DIR__ . '/../../../../../vendor/mageekguy.atoum.phar';

use Jedi\AtoumBundle\Tests\Units;

class helloWorld extends Units\Test
{
}

Web test case

You can create easily a kernel environment :

<?php

require __DIR__ . '/../../../../../../../vendor/autoload.php';

use Jedi\AtoumBundle\Tests\Units;

class helloWorld extends Units\WebTestCase
{
    public function testMyTralala()
    {
        $client = self::createClient();
    }
}

Known issues

Test a controller

You can test your controller with the ControllerTest class (it extends WebTestCase) :

<?php

namespace vendor\FooBundle\Tests\Controller;

use Jedi\AtoumBundle\Tests\Units\WebTestCase;
use Jedi\AtoumBundle\Tests\Controller\ControllerTest;

class BarController extends ControllerTest
{
    //test a json api method
    public function testGet()
    {
        $client   = static::createClient();
        $crawler  = $client->request('GET', '/api/foobar');
        $response = $client->getResponse();

        $this
            ->integer($response->getStatusCode())
                ->isEqualTo(200)

            ->string($response->headers->get('Content-Type'))
                ->isEqualTo('application/json')
        ;
    }
}