First-class PHP Continuous Integration using TeamCity
A while ago we blogged about using TeamCity to do Continuous Integration for PHP. TeamCity developers never seem to sleep: with TeamCity 8 a new feature called meta-runners was introduced. Meta runners allow us to reuse build steps by representing them as a native TeamCity runner. In other words, they allow us to make several build steps easier. Which is exactly what we decided to do: create some meta runners based on our previous blog post and make it really easy to run several PHP-related build steps.
The Meta-runner Power Pack for TeamCity 8 contains a set of PHP-related meta runners:
- Run arbitrary PHP code using the PHP runner
- Install a specific Composer dependency using the Install Composer package runner
- Install/update packages from composer.json using the Run Composer runner
- Run Phing build script using the Phing runner
- Run PHPUnit tests (with code coverage reporting) using the PHPUnit runner
There is only one requirement: a PHP runtime should be installed on our build agent. The Phing, PHPUnit and Composer meta runners will automatically download the latest versions of the executables during the build! Full documentation for these PHP meta runners is available on GitHub.
Installing meta runners
After downloading the PHP meta-runners from GitHub, all files named MRPPPHP<name>.xml should be copied into the <TeamCity Data Directory>/projects/<Project ID>/pluginData/metaRunners/ directory on our TeamCity server.
Once this is done, the TeamCity server will list these new meta-runners under the administration page for the project in which the meta runners have been installed:
Using the PHPUnit runner
Since a big part of Continuous Integration is making sure the quality of our software is high, running unit tests is typically part of a build configuration. In the PHP world we typically use PHPUnit for this.
The PHPUnit runner allows running PHPUnit tests during the build and will optionally publish code coverage results to TeamCity. A build step using this runner will use a PHPUnit executable available on the build agent if specified, or automatically download the latest phpunit.phar from the PHPUnit.de website during the build.
To run unit tests, all we have to do is specify the path to our unit tests (but don’t worry, we can also tweak PHPUnit parameters):
This will run and report back unit test results to the TeamCity server.
And if we enable the Collect code coverage option, we get code coverage reports integrated with TeamCity as well:
Bugfixes and improvements for these meta runners (or your own, PHPLint and phpDocumentor runners would be nice!) are welcome through our GitHub repository.
Haven’t tried TeamCity? Give it a shot! It’s 100% free for up to 20 build configurations.
Let us know your thoughts through the comments below!
– The TeamCity Team
Subscribe to Blog updates
Thanks, we've got you!