facile-it / symfony-functional-testcase
A small functional base test case for Symfony
Installs: 6 797
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 180
Open Issues: 0
Requires
- php: ^7.2|^8.0
- symfony/framework-bundle: ^3.4|^4.0|^5.0
Requires (Dev)
- facile-it/facile-coding-standard: ^0.4
- jangregor/phpstan-prophecy: ^0.8.1
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^0.12.55
- phpstan/phpstan-phpunit: ^0.12.16
- phpunit/phpunit: ^7.5.20|^8.5.14|^9.5.2
- symfony/browser-kit: ^3.4|^4.0|^5.0
- symfony/console: ^3.4|^4.0|^5.0
- symfony/monolog-bridge: >=3
- symfony/monolog-bundle: ^3.1.2
- symfony/phpunit-bridge: ^5.1.8
- symfony/security-bundle: ^3.4|^4.0|^5.0
- symfony/security-core: ^3.4|^4.0|^5.0
- symfony/yaml: ^3.4|^4.0|^5.0
Suggests
- facile-it/paraunit: A PHPUnit wrapper to execute tests in parallel
README
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.
Installation
$ composer require --dev facile-it/symfony-functional-testcase
Usage
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 {
Functionalities
Check HTTP status codes
isSuccessful()
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()
:
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