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.

image

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 MRPP_PHP_<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:

image

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):

image

This will run and report back unit test results to the TeamCity server.

image

And if we enable the Collect code coverage option, we get code coverage reports integrated with TeamCity as well:

image

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!

Happy building!
– The TeamCity Team

This entry was posted in Features, How-To's, Tips&Tricks and tagged , , , , , , . Bookmark the permalink.

6 Responses to First-class PHP Continuous Integration using TeamCity

  1. Pingback: Deploying Committed Changes to a Remote Server | JetBrains PhpStorm Blog

  2. Juan says:

    Thanks a lot for these new PHP friendly features. Ive used TeamCity a lot when working with Java based projects, and im really happy to see that you are working to leverage PHP CI capabilities on it. Congratz!

  3. Juan says:

    Just a small fix: The URI where xmls of meta runners should be copied is wrong. The correct one is /config/projects//pluginData/metaRunners/

  4. sergey says:

    PHPUnit fails with “tccoverage does not exist”
    http://shot.gourry.ru/20140205-qkg-159kb.jpg
    How can i fix it?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>