Earlier today I introduced why and how we initially integrated the Symfony2 testing mechanism into symfony 1.X : in order to make this piece of software as clean and evolvable as possible I just isolated it and made a small repo on Github.
SfCcTesting
SfCcTesting – Symfony 1.X Client-Crawler Testing – is a small library (2 classes and a configuration file) which lets you write functional tests, in symfony 1.X, a là Symfony2.
if you take a look at the repository’s README you will find the basic instructions to start writing your tests: keep in mind that – although it’s usable on old-school symfony projects (svn etc) – you should install it with Git and manage dependencies and updates with Composer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Each test needs to implement 2 protected methods, getApplication()
and
bootstrapSymfony()
.
The getApplication
method defines the application to bootstrap symfony for,
and should be defined in an ApplicationWebTestCase
class, like in the following
example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
so your test files become leaner:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
The bootstrapSymfony()
method, instead, includes the bootstrap for the symfony
application in the test environment; you are allowed to redefine the location
of the bootstrap in order not to force you to follow a unique directory
structure convention.
The bootstrapSymfony()
method should be placed in a BaseWebTestCase
of
our test suite:
1 2 3 4 5 6 7 8 9 10 11 |
|
so your different ApplicationWebTestCase
can share the same bootstrap file:
1 2 3 4 5 6 7 8 9 10 11 |
|
1 2 3 4 5 6 7 8 9 10 11 |
|
That’s all folks: with just a bunch of lines of code you are able to functionally test a symfony 1.X application with the Symfony2 DomCrawler.
Feel free to rant and, if you want, you can already rely on this small library via Packagist.