PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1
CHAPTER 20 ■ CONTINUOUS INTEGRATION

return $suite;
}
}


■Note In in this case I've kept my test classes in the global namespace. Where tests have a close or one to one


relationship to the components they test, however, it's often neater to place each test class in the same


namespace as its target, and in a parallel directory structure. That way you can tell at a glance the relationship


between a test and its subject both from the test's namespace and the location of its file.


The PHPUnit_Framework_TestSuite class allows you to collect individual test cases into a suite. Here’s
how I can call this from the command line:


$ phpunit test/UserTests


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


Documentation


Transparency is one of the principles of CI. When you're looking at a build in a Continuous
Integration environment, therefore, it’s important to be able to check that the documentation is up to
date, and covers the most recent classes and methods. I examined phpDocumentor in Chapter 16, so
I’ve already run an install like this.


pear upgrade PhpDocumentor


I’d better run the tool just to be sure:

$ mkdir docs
$ phpdoc --directory userthing --target docs/


That generates some pretty bare documentation. Once that’s published on a CI server, I’m sure to
be shamed into writing some real inline documentation.


Code Coverage


It’s no good relying on tests if they don’t apply to the code you have written. PHPUnit includes the
ability to report on code coverage. Here's an extract from PHPUnit’s usage information.


--coverage-html

Generate code coverage report in HTML format.
--coverage-clover Write code coverage data in Clover XML format.
--coverage-source Write code coverage / source data in XML format.

Free download pdf