2017 © Pedro Peláez
 

library symfony-testing-tools

Symfony testing tools

image

intaro/symfony-testing-tools

Symfony testing tools

  • Friday, March 25, 2016
  • by muxx
  • Repository
  • 2 Watchers
  • 0 Stars
  • 8,169 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 3 % Grown

The README.md

Symfony testing tools

The library contains improved classes of WebTestCase and Container for convenient testing., (*1)

Features

The Client local caching

Web Client is caching in WebTestCase. If you want to get a client you should use:, (*2)

$client = static::getClient();

If you want to get a new client you should use:, (*3)

$client = static::getClient(true);

Full example:, (*4)

<?php
namespace Foo\BarBundle\Tests\Controller;

use Intaro\SymfonyTestingTools\WebTestCase;

class SomeControllerTest extends WebTestCase
{
    public function testIndex()
    {
        $client = static::getClient(true);
        //...
    }
}

Shortcuts for EntityManager and Container

You can simply get EntityManager or Container in the current context:, (*5)

<?php
namespace Foo\BarBundle\Tests\Controller;

use Intaro\SymfonyTestingTools\WebTestCase;

class SomeControllerTest extends WebTestCase
{
    public function testIndex()
    {
        $client = static::getClient(true);

        $em = static::getEntityManager();
        $service = static::getContainer()->get('some_service');
        //...
    }
}

Checking a response HTTP code

You can check response result with the following methods:, (*6)

<?php

namespace Foo\BarBundle\Tests\Controller;

use Intaro\SymfonyTestingTools\WebTestCase;

class SomeControllerTest extends WebTestCase
{
    public function testIndex()
    {
        $client = static::getClient();

        $client->request('GET', '/foo/bar/index');
        $this->assertResponseOk($client->getResponse(), 'Page opens');
        $this->assertResponseRedirect($client->getResponse(), 'Page redirects to other page');
        $this->assertResponseNotFound($client->getResponse(), 'Page not found');
        $this->assertResponseForbidden($client->getResponse(), 'Page forbidden');
        $this->assertResponseCode(201, $client->getResponse(), 'JSON returned', 'application/json');
    }
}

Fixtures appending

You can add fixtures before test running:, (*7)

<?php

namespace Foo\BarBundle\Tests\Controller;

use Foo\BarBundle\DataFixtures\ORM\Test\ActionRecordData;
use Intaro\SymfonyTestingTools\WebTestCase;

class SomeControllerTest extends WebTestCase
{
    public static function setUpBeforeClass()
    {
        static::appendFixture(new ActionRecordData, [
            'purge' => true,
        ]);
    }

    public function testIndex()
    {
        //...
    }
}

The Versions

25/03 2016

dev-master

9999999-dev

Symfony testing tools

  Sources   Download

MIT

The Requires

 

phpunit testing symfony2 symfony

25/03 2016

v0.1

0.1.0.0

Symfony testing tools

  Sources   Download

MIT

The Requires

 

phpunit testing symfony2 symfony