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.
Example 5-1. PHP Project Wizard's command-line options
ppw --help
PHP Project Wizard (PPW) 1.1.0 by Sebastian Bergmann.
Usage: ppw [switches] <directory>
--name <name> Name of the project
--source <directory> Directory with the project's sources (default: src)
--tests <directory> Directory with the project's tests (default: tests)
For multiple directories use a comma separated list
--bootstrap <script> PHPUnit bootstrap script (default: tests/autoload.php)
--phpcs <ruleset> Ruleset for PHP_CodeSniffer (default: build/phpcs.xml)
--phpmd <ruleset> Ruleset(s) for PHPMD (default: build/phpmd.xml)
--apidoc-tool <tool> Tool to use for API documentation (default: phpdox)
Possible values are "phpdoc", "phpdox"
--disable-apidoc Do not include API documentation in the build script
--disable-phpab Do not include PHPAB in the build script
--force Overwrite existing files
--help Prints this usage information
--version Prints the version and exits
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.