dev-master
9999999-devSymfony testing tools
MIT
The Requires
phpunit testing symfony2 symfony
v0.1
0.1.0.0Symfony testing tools
MIT
The Requires
phpunit testing symfony2 symfony
Wallogit.com
2017 © Pedro Peláez
Symfony testing tools
The library contains improved classes of WebTestCase and Container for convenient testing., (*1)
Web Client is caching in WebTestCase. If you want to get a client you should use:, (*2)
$client = static::getClient();
If you want to get a new client you should use:, (*3)
$client = static::getClient(true);
Full example:, (*4)
<?php
namespace Foo\BarBundle\Tests\Controller;
use Intaro\SymfonyTestingTools\WebTestCase;
class SomeControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::getClient(true);
//...
}
}
You can simply get EntityManager or Container in the current context:, (*5)
<?php
namespace Foo\BarBundle\Tests\Controller;
use Intaro\SymfonyTestingTools\WebTestCase;
class SomeControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::getClient(true);
$em = static::getEntityManager();
$service = static::getContainer()->get('some_service');
//...
}
}
You can check response result with the following methods:, (*6)
<?php
namespace Foo\BarBundle\Tests\Controller;
use Intaro\SymfonyTestingTools\WebTestCase;
class SomeControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::getClient();
$client->request('GET', '/foo/bar/index');
$this->assertResponseOk($client->getResponse(), 'Page opens');
$this->assertResponseRedirect($client->getResponse(), 'Page redirects to other page');
$this->assertResponseNotFound($client->getResponse(), 'Page not found');
$this->assertResponseForbidden($client->getResponse(), 'Page forbidden');
$this->assertResponseCode(201, $client->getResponse(), 'JSON returned', 'application/json');
}
}
You can add fixtures before test running:, (*7)
<?php
namespace Foo\BarBundle\Tests\Controller;
use Foo\BarBundle\DataFixtures\ORM\Test\ActionRecordData;
use Intaro\SymfonyTestingTools\WebTestCase;
class SomeControllerTest extends WebTestCase
{
public static function setUpBeforeClass()
{
static::appendFixture(new ActionRecordData, [
'purge' => true,
]);
}
public function testIndex()
{
//...
}
}
Symfony testing tools
MIT
phpunit testing symfony2 symfony
Symfony testing tools
MIT
phpunit testing symfony2 symfony