Generally, it’s not a good idea to unit test protected or private methods, but in some cases it could be useful. Of course we don’t want to change our class contract, and expose those methods as a public ones, just becasue we want to test them with PHPUnit. This case can be solved with Proxy-Object library. It provides easy-to-use way to get protected classes to the surface. More about that is here http://blog.bastian-feder.de/blog/029_proxyObject.html. Here I’ll show how to integrate proxy object into your Symfony2 application:

1. Extend your deps file:

[gist id=”1307253″]

2. Run vendors update

[gist id=”1307262″]

3 . Put proxy-object to the autoloader (there’s tricky part, which took me a while to manage how to do it properly)

[gist id=”1307252″]

From now on you can use Proxy-Object like in example on Bastian’s blog or like this:

[gist id=”1307267″]

As you can see, it’s easy and nice way to test your system properly.