This last 6 months, I had the chance to use many new & cool tools for PHP:
Composer, the ultimate dependency manager for PHP projects. If you’re not already using it, I strongly encourage you to test it ASAP.
Symfony framework, I started to work with the first version 3 years ago and this new version is a master piece, even Drupal announced that the next version will rely on it.
Atoum, as mentioned in my previous post, I moved away from PHPUnit for this new unit tests framework.
phpDocumentor, if you missed the big news: DocBlox and phpDocumentor merged and the alpha preview of the next version is already awesome.
Previously, our Symfony projects used git submodule, PHPUnit and DocBlox, so I had to update our CI configuration (Jenkins and Sonar). In fact, it was pretty easy because all our builds are managed by a custom version of the excellent php jenkins template. Here’s a quick list of the updates for this new stack.
Add atoum dependency with composer
The standard edition of Symfony relies on composer, it’s trivial to add atoum. Yet William Durand suggested a nice practice: add this “dev” dependency in the suggested packages instead of the required packages. This way, your production stage avoid useless packages and you just need an argument to fetch the optional packages “php composer.phar install —install-suggest”.
Create an abstract test class
Atoum code convention is “full lower case” and the test framework expects your tests to live in a namespace “tests/units”. Since Symfony uses capitalized namespaces, we have to make some adjustments:
This abstract class will be extended by all our test classes, it redefines the “expected” namespace for atoum to “Tests\Units”. Since there is no Symfony AtoumBundle for the moment, this class should live in a bundle (to be autoloaded).
Create the atoum configuration file
As PHPUnit, atoum accepts a configuration file conventionally named “.atoum.php” at your project root. I only use this configuration file for the remote CI plateform, so I named this file “.atoum.ci.php” and I define some specific reports (xunit, clover, coverage).
Warning, at the moment xunit and clover reports are wip. It will be merged soon, yet to ease our processes, Plemi provides a fork with a branch “clover-xunit” including all of these features.
Add composer step to ant
Nothing magic here, we just need to download composer and run the dependencies installation. Yet don’t forget to update the “clean” task (to remove the composer files).
Add atoum step to ant
Again, as PHPUnit, atoum provides also a CLI. The -g/—glob options was added recently, and allows regex pattern and wildcard char. For the bootstrap file, be lazy, just use the app/bootstrap.php.cache generated by Symfony. Note: if you didn’t place the previous abstract tests class in a bundle, you should handle this file manually. Here’s the ant target in my build.xml file:
Add phpDocumentor step to ant
phpDocumentor is installed with PEAR, so the only thing we need is an Ant step to generate the code documentation. Good news: the CLI argument are exactly the same as DocBlox.
That’s it! if you already used the php-jenkins template before, you should be able to have all your previous metrics in your jenkins job. You may notice that the “clover HTML report” is a bit different, it’s not generated with PHP CodeCoverage anymore but with the native html report writer from atoum.
What about Sonar ? Since the version 2.14, I wasn’t able to import the clover xml reports generated by atoum, It’s because PHPUnit doesn’t generate a standard clover file and so the sonar plugin isn’t able to parse the standard file from atoum. Hopefully, Julien Bianchi is working hard on atoum integration in sonar with a plugin and will release it in “the next days”.
Bonus track #1: To run atoum test in your local environment, here’s the command:
Bonus track #2: here’s is a full template of an ant build.xml for a Symfony project using composer, atoum and phpDocumentor 2 (used by Plemi)