A small functional base test case for Symfony

1.3.0 2024-03-15 08:18 UTC


Build status Latest Stable Version Latest Unstable Version Codecov coverage status

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:


namespace Tests;

-use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
+use Facile\SymfonyFunctionalTestCase\WebTestCase;

class SomeTest extends WebTestCase


Check HTTP status codes


Check that the request succedded:

$client = $this->makeClient();
$client->request('GET', '/contact');

// Successful HTTP request

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

Command Tests

TODO document runCommand