This is a small base TestCase for PHPUnit functional tests in Symfony that provides a simple getContainer()
helper,
alongside with some small caching to speed up the tests.
Forked (and slimmed down) from liip/LiipFunctionalTestBundle.
$ composer require --dev facile-it/symfony-functional-testcase
To use this in one of your functional tests, you just have to edit it like this:
<?php
namespace Tests;
-use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
+use Facile\SymfonyFunctionalTestCase\WebTestCase;
class SomeTest extends WebTestCase
{
Check that the request succedded:
$client = $this->makeClient();
$client->request('GET', '/contact');
// Successful HTTP request
$this->isSuccessful($client->getResponse());
Add false
as the second argument in order to check that the request failed:
$client = $this->makeClient();
$client->request('GET', '/error');
// Request returned an error
$this->isSuccessful($client->getResponse(), false);
In order to test more specific status codes, use assertStatusCode()
:
Check the HTTP status code from the request:
$client = $this->makeClient();
$client->request('GET', '/contact');
// Standard response for successful HTTP request
$this->assertStatusCode(302, $client);
TODO document runCommand