facile-it/symfony-functional-testcase

A small functional base test case for Symfony

1.3.0 2024-03-15 08:18 UTC

This package is auto-updated.

Last update: 2024-10-18 08:43:13 UTC


README

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.

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