Chapter 5. Automating the Automation

Over the course of the last two years I have successfully set up many Jenkins-based continuous integration environments for PHP projects. As I was going through the same manual steps (ironically, to set up an automated process) over and over again, I asked myself: would it not be nice if there were a standard for the build automation and continuous integration of PHP projects as well as tooling to support it?

Answering this question lead to the creation of two new open source projects that are the topic of this chapter: the PHP Project Wizard and the Template for Jenkins Jobs for PHP Projects.

The PHP Project Wizard (PPW) is a command-line tool that can be used to generate the scripts and configuration files necessary for the build automation of a PHP project.

The following two commands are all that is required to install the PHP Project Wizard using the PEAR Installer:

pear config-set auto_discover 1
pear install pear.phpunit.de/ppw

As you can see in Example 5-1, the scripts and configuration files generated by the PHP Project Wizard can be configured using various command-line options.

ppw --name bankaccount
PHP Project Wizard (PPW) 1.1.0 by Sebastian Bergmann.

Wrote build script for Apache Ant to /home/sb/bankaccount/build.xml
Wrote configuration for PHP_CodeSniffer to /home/sb/bankaccount/build/phpcs.xml
Wrote configuration for PHPMD to /home/sb/bankaccount/build/phpmd.xml
Wrote configuration for PHPUnit to /home/sb/bankaccount/phpunit.xml.dist
Copied templates for PHPAB to /home/sb/bankaccount/build

The only mandatory command-line option for ppw is --name which is used to set the name of the project. The tool is usually invoked in the project's root directory. By default, it expects the production code to be in a src directory and the test code to be in a tests directory.

Example 5-2 shows the files generated by the PHP Project Wizard and Example 5-3 lists the artifacts generated during the build.

These build artifacts should be excluded from version control and be added to .gitignore, for instance, to prevent developers from accidentally adding such files to the repository. The Template for Jenkins Jobs for PHP Projects which we discuss in the next section expects exactly these build artifacts in exactly these locations.