hautelook/frankenstein

The creature that is summoned by mixing PHPUnit, Prophecy, Atoum.

0.1.2 2014-06-03 04:34 UTC

README

Build Status Scrutinizer Quality Score Latest Unstable Version

This let you use PHPUnit with Prophecy mocks and Atoum asserters.

Usage

Your test class must extend Hautelook\Frankenstein\TestCase:

<?php

namespace AcmeDemoBundle\Tests\Foo;

use Hautelook\Frankenstein\TestCase;

class BarTest extends TestCase
{

}

When extending from the provided TestCase everything else than Atoum asserters and Prophecy mocks are restricted.

You will have to use Prophecy to mock, using $this->prophesize():

public function test()
{
    $routerProphecy = $this->prophesize('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
    $routerProphecy
        ->generate('acme_demo_index')
        ->willReturn('/acme')
    ;

    $foo = new Foo($routerProphecy->reveal());
}

You will have to use atoum asserters instead of phpunit's:

public function test()
{
    $foo = new Foo();

    $this
        ->string($foo->getName())
            ->isEqualTo('foo foo foo')
    ;
}

Prophecy arguments

The test class let you access the Prophecy\Argument shortcut methods through $this->arg or $this->arg():

public function test()
{
    $routerProphecy = $this->prophesize('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
    $routerProphecy
        ->generate($this->arg->type('string'))
        ->willReturn('/acme')
    ;

    $foo = new Foo($routerProphecy->reveal());
}

Running the Tests

Install the Composer dev dependencies:

php composer.phar install

Then, run the test suite using phpunit:

bin/phpunit

License

Frankenstein is released under the MIT License. See the bundled LICENSE file for details.

Credits

This library has copies of code https://github.com/atoum/atoum and uses https://github.com/phpspec/prophecy-phpunit .