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.


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


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


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


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.


  • 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