PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1

CHAPTER 20 ■ CONTINUOUS INTEGRATION


You may have noticed that I moved the code for userthing into a directory named trunk. That’s
because I’m going to import the project into Subversion, and the branches, tags and trunk directories
are a useful convention in that system.
Here’s the import:


$ svn import userthing.orig/ file:///var/local/svn/userthing -m'first import'


And here's the checkout.

$ svn checkout file:///var/local/svn/userthing/trunk userthing


I covered Subversion in more detail in Chapter 17.
Now that I have the a local version of my project, I’m going to change my working directory to src/
in order to try out the various tools that my CI implementation will require.


$ cd userthing/src


Unit Tests


Unit tests are the key to continuous integration. It’s no good successfully building a project that
contains broken code. I covered unit testing with PHPUnit in Chapter 18. If you’re reading out of order,
though, you’ll want to install this invaluable tool before proceeding.


$ pear channel-discover pear.phpunit.de
$ pear install phpunit


Also in Chapter 18 I wrote tests for a version of the userthing code I’ll be working with in this
chapter. Here I run them once again, to make sure my reorganization has not broken anything new.


$ phpunit test


PHPUnit 3.4.11 by Sebastian Bergmann.
.....
Time: 0 seconds, Memory: 4.50Mb
OK (5 tests, 6 assertions)


As you can see, I referenced the filesystem to invoke my tests. I passed the test directory as an
argument to PHPUnit, and it automatically sought out my test files. However, one of the CI tools you’ll
encounter later, phpUnderControl, prefers that you reference a single class in order to run tests. To
support this requirement, I can add a test suite class. Here is UserTests.php:


require_once 'PHPUnit/Framework.php';
require_once 'test/UserStoreTest.php';
require_once 'test/ValidatorTest.php';


class UserTests {


public static function suite() {
$suite = new PHPUnit_Framework_TestSuite();
$suite->addTestSuite('UserStoreTest');
$suite->addTestSuite('ValidatorTest');

Free download pdf