facile-it/symfony-functional-testcase

A small functional base test case for Symfony

0.1.1 2019-03-13 15:35 UTC

This package is auto-updated.

Last update: 2020-01-08 16:21:21 UTC


README

Build status Latest Stable Version Latest Unstable Version 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.

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