Test Extension

Set of tools to make unit testing of Symfony2 applications easier with PHPUnit and Phake

We love unit testing and use PHPUnit and the Phake mocking library for our testing. However there was some testing functionality that we used over and over again in many of our tests. To make life easier we are extracting this to it's own library and making it available to everyone.

Install

Add the package brown298/test_extension to your composer.json in the require-dev section

{
    "require-dev" : {
        "brown298/test_extension": "*"
    }
}

For more information about Composer, please visit http://getcomposer.org

Usage

Replace the "extends PHPUnit_Framework_TestCase" on each of your tests with the most appropriate abstract class.

For example:

class aTest extends \PHPUnit_Framework_TestCase

Becomes

use Brown298\TestExtension\Test\AbstractTest;
class aTest extends AbstractTest

Reflection

One of the largest pieces of code repetition we found in our tests was implementing reflection to access protected properties/functions. To fix this, we implemented a set of functions to create the reflection objects and access the property/function.

Functions

  • getProtectedValue ($object, $property) - returns the protected property requested.
  • setProtectedValue ($object, $property, $value) - changes the protected property.
  • callProtected ($object, $methodName, array $args) - calls a protected function using the array of arguments