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 Here I’ll show how to integrate proxy object into your Symfony2 application:

1. Extend your deps file:

2. Run vendors update

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

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

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