Testing in isolation with Symfony2 and WebTestCase

It’s extremely important to have same state of the System Under Test. In most of the cases it will be possible by having same contents in a database for every test. I’ve decribed how to achieve it in Fully isolated tests in Symfony2 blog post about two years ago (btw. it’s most popular post on this blog). It was the time, when PHP’s Traits weren’t that popular.

Read more

Use Proxy-Object in Symfony2 applictions to test non-public methods

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:

Read more

Fully isolated tests in Symfony2

The most important thing you should provide with your re-usable bundles is unit tests set. Lately I solved two major cases which Symfony2 hasn’t got out of the box: testing services, defined in Dependency Injection Container and running model tests with fixtures in fully isolated environment.

The most important thing you should provide with your re-usable bundles is unit tests set. Lately I solved two major cases which Symfony2 hasn’t got out of the box: testing services, defined in Dependency Injection Container and running model tests with fixtures in fully isolated environment.

Read more