2017 © Pedro Peláez
 

library paraunit-testcase

paraunit testcase

image

facile-it/paraunit-testcase

paraunit testcase

  • Friday, September 22, 2017
  • by Jean85
  • Repository
  • 4 Watchers
  • 6 Stars
  • 9,025 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 1 Forks
  • 4 Open issues
  • 17 Versions
  • 5 % Grown

The README.md

paraunit-testcase

WARNING: this package is now abandoned; we suggest dama/doctrine-test-bundle as a replacement instead., (*1)

Stable release Unstable release, (*2)

[![Scrutinizer][Master scrutinizer image]][Master scrutinizer link], (*3)

TestCase and HTTP client to test Symfony2/3 applications with Doctrine database isolation:, (*4)

  • no more manual database cleanup after each test, it's already done!
  • no more garbage left over in your test database
  • mess all you want with your fixtures
  • (a bit) faster functional tests

Requirements

This package is meant to be used for functional testing inside Symfony2/3+Doctrine applications. It works only with transactional databases, so Entity Manager only, sorry!, (*5)

If you need to test controllers that requires authentication, it's best to set the security to HTTP-basic in your test environment, to speed up the test and avoid re-testing the login functionality of your app; if this isn't viable for you, see Advanced usage., (*6)

It's suggested in combination with facile-it/paraunit, for even more faster testing!, (*7)

Installation

To use this package, use composer:, (*8)

  • from CLI: composer require --dev facile-it/paraunit-testcase
  • or, directly in your composer.json:
{
    "require-dev": {
        "facile-it/paraunit-testcase": "~0.4"
    }
}

Usage

This package provides a test case class, ParaunitFunctionalTestCase: to achieve per-test-method transactional isolation, extend you functional test classes from it., (*9)

With this, anything that your test writes on the DB:, (*10)

  • is normally readable everywhere inside your test method
  • is "forgotten" at the end of the test method: the first-level transaction is always rolled back
  • is faster to write (it doesn't really reach the DB)
  • your app will behave normally: it can open and close more transactions, and it will fail as normal when flushing incorrect/incomplete data

Testing a controller

The TestCase provides some utility methods for testing controller's actions:, (*11)

  • getUnauthorizedClient(): extended Symfony HTTP client, for controller testing (it can read inside the transaction, even between multiple requests)
  • getAuthorizedClient($user, $password): same as before, but with HTTP basic authentication
  • getEM(): Doctrine's Entity Manager (transactional)
  • refreshEntity(&$entity, $entityManagerName = null): shortcut for refreshing an entity, re-fetching all the data from the database; really useful if you need to run some assertion on an entity and you want to be sure to read the data as persisted/rollbacked on the database.

Testing a Console ContainerAwareCommand

We also provide an easy way to test in parallel easily console ContainerAwareCommand. To do it use the the ParaunitFunctionalTestCase::runContainerAwareCommandTester() method, like this:, (*12)

class YourCommandTest extends ParaunitFunctionalTestCase
{
    public function testYourCommand()
    {
        $output = $this->runContainerAwareCommandTester(
            new YourCommand(), 
            [
                'argument' => 'argumentValue',
                '--option' => 0,
            ]
        );

        $this->assertContains('Execution completed', $output);
    }
}

If you want to split the instantiation and the execution (i.e. if you need to interact with the container first), you can use the createContainerAwareCommandTester() method to get a ContainerAwareCommandTester class like this:, (*13)

class YourCommandTest extends ParaunitFunctionalTestCase
{
    public function testYourCommand()
    {
        $commandTester = $this->createContainerAwareCommandTester(new YourCommand());
        $container = $commandTester->getCommandContainer();
        // do what you want to the container!

        $commandTester->execute(
            [
                'argument' => 'argumentValue',
                '--option' => 0,
            ]
        );

        $this->assertEquals(0, $commandTester->getStatusCode());
        $this->assertContains('Execution completed', $commandTester->getDisplay());
    }
}

Note: the ContainerAwareCommandTester class which the method returns extends Symfony's CommandTester class, so you can use it in the same way (see the assertions); the only difference is that it provides the same level of transactional isolation as our test case or client., (*14)

Advanced usage

It's possible to extend ParaunitFunctionalTestCase more before using it as your base test case:, (*15)

  • extend and use the prepareAuthorizedClient(...) hook method to add additional authentication and preparation to the client, if needed
  • do NOT EVER FORGET to call the parent methods first if you override the setUp() and tearDown() methods

The Versions

22/09 2017

dev-master

9999999-dev http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

04/07 2017

0.5.5

0.5.5.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

26/05 2017

0.5.4

0.5.4.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

26/05 2017

0.5.3

0.5.3.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

11/04 2017

0.5.2

0.5.2.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

04/04 2017

0.5.1

0.5.1.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

03/11 2016

0.5

0.5.0.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

04/10 2016

dev-README-patch-1

dev-README-patch-1 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

22/09 2016

0.4

0.4.0.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

16/09 2016

0.3

0.3.0.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

22/08 2016

0.2

0.2.0.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

22/08 2016

dev-write_resistent_connection

dev-write_resistent_connection http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

14/03 2016

0.1.4

0.1.4.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

10/03 2016

0.1.3

0.1.3.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

10/03 2016

0.1.2

0.1.2.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

08/01 2016

0.1.1

0.1.1.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case

08/09 2015

0.1

0.1.0.0 http://github.com/facile-it/paraunit-testcase

paraunit testcase

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by Alessandro Lai

phpunit doctrine symfony transaction isolation parallel test test case