Installing PHPUnit for PHP 5.3 on ZendServer

ZendServer installs PHP CLI as part of the installation, and, as is customary for PHP 4.3+, includes a PEAR installer. It’s a good idea to install PEAR before installing PHPUnit as per the recommendation here.

  1. Open Zend\ZendServer\bin\go-pear.bat and change the line:
    %PHP_BIN% -d output_buffering=0 -d PEAR\go-pear.pharto (see PHAR Runtime Configuration):%PHP_BIN% -d output_buffering=0 -d phar.require_hash=0 PEAR\go-pear.pharThis will stop the fatal error:phar...does not have a signatureas by default PHP will not process a PHAR archive without a signature.
  2. Run go-pear.bat

    For Windows 7, make sure you open the console as an administrator, or the installer won’t be able to create some folders in the default install locations. At the command prompt enter:#cd \program files\zend\zendserver\bin
    # go-pear.bat
    and you should get something like this (I selected the system-wide install and accepted the default locations):

via Installing PHPUnit for PHP 5.3 on ZendServer |

Search each class for function names that match except for the underscore prefix

Bill Karwin posts a useful little snippet that will list and search each class for function names that match except for the underscore prefix, private / protected functions.

< ?php /** * Find methods that differ only by the underscore prefix. * by Bill Karwin August 2010 * * I release this code under the terms of the New BSD License: * */ // Change this to suit your environment define("LIBRARY_DIR", "/Users/bill/Library/PHP/ZF/library"); // Pre-load some files to satisfy the autoloader. // We could also add the local PEAR library dir to the autoloader. require_once("PHPUnit/Framework/SelfDescribing.php"); require_once("PHPUnit/Framework/AssertionFailedError.php"); require_once("PHPUnit/Framework/Assert.php"); require_once("PHPUnit/Framework/Test.php"); require_once("PHPUnit/Extensions/Database/DataSet/ITable.php"); require_once("PHPUnit/Extensions/Database/DataSet/AbstractTable.php"); require_once("PHPUnit/Extensions/Database/DataSet/IDataSet.php"); require_once("PHPUnit/Extensions/Database/DataSet/AbstractDataSet.php"); require_once("PHPUnit/Extensions/Database/ITester.php"); require_once("PHPUnit/Extensions/Database/AbstractTester.php"); require_once(LIBRARY_DIR . "/Zend/Loader/Autoloader.php"); Zend_Loader_Autoloader::getInstance(); // Find every PHP file under the library dir and slurp them in. // Yes that's a lot of files. Deal with it. $Directory = new RecursiveDirectoryIterator(LIBRARY_DIR); $Iterator = new RecursiveIteratorIterator($Directory); $Regex = new RegexIterator($Iterator, '/^.+\.php$/i'); foreach ($Regex as $filename) { require_once($filename); } // Loop over each class now in the PHP runtime. // Filter by classes named Zend*. $classes = get_declared_classes(); $zendclasses = new RegexIterator(new ArrayIterator($classes), '/ ^Zend/'); foreach ($zendclasses as $classname) { // Search each class for function names that match except for the underscore prefix // Note this includes duplicates and magic methods, so you have to do some sorting // on the output. Hint: `sort -u`. $class = new ReflectionClass($classname); $methods = $class->getMethods();
foreach ($methods as $method) {
if (preg_match("/^__*(.*)/", $method->name, $matches)) {
$underscore = $method;
if ($class->hasMethod($matches[1])) {
$nonunderscore = $class->getMethod($matches[1]);
echo $underscore->getDeclaringClass()->name
. "::" . $underscore->name . "()" . " => ";
if ($underscore->getDeclaringClass() != $nonunderscore->getDeclaringClass()) {
echo $nonunderscore->getDeclaringClass()->name;
echo "::" . $nonunderscore->name . "()" . "\n";


Acceptance Test-Driven Development

Giorgio Sironi writes an interesting TDD story; I am halfway through reading Growing object-oriented software, guided by tests, a book that teaches Test-Driven Development in a Java environment. A review will come soon, since the process described in this work is really language-agnostic and interesting also for php developers.

However, the book’s authors introduce a very productive practice, which consists in a double cycle of TDD:

* a longer cycle, where you write acceptance (aka end-to-end) tests, deriving them from the user stories or formal requirements, and make them pass;

* a shorter cycle contained in the first, which happens in the phase when an acceptance test is red: you write unit tests and make them pass until the related acceptance test does not fail anymore.

Read complete story @ PHP Zone.

Talk: PHP Best Practices – Matthew Weier O’Phinney and Lorna Jane Mitchell

Writing maintainable code is an art that takes effort and practice to master.
Part of that art is learning what tools and strategies will assist you in that effort. In this tutorial, we will cover a variety of practices and tools that can make your life, and the lives of your team members, easier as you develop your applications. Among them, we will provide overviews of:

  • Version Control
  • Coding Standards
  • Unit Testing basics
  • QA tools: phpcs, phploc, phpmd, continuous integration, and more
  • Team Collaboration tools, such as Skype, IRC, issue trackers, and more

via Talk: PHP Best Practices –

PHP Continuous Integration with Atlassian Bamboo

Mike Willbanks writes; Continuous integration is all the rage these days; you are unit testing your code are you not? During some consulting in January with the help of Sebastian Bergmann, from, we setup continuous integration utilizing Atlassian Bamboo and received training on PHPUnit.

Using Atlassian Bamboo for continuous integration will take you a bit to setup, however, I have found it to be an invaluable tool when utilizing the Atlassian stack (JIRA, Confluence, Crucible, Bamboo and Crowd).


This posting assumes the following:

  • You have Atlassian Bamboo setup
  • Ant is available on the system
  • You already have PHPUnit setup for your project
  • You have selected a coding standard

This posting will go over the following:

  • Getting Started
  • PHP Depend
  • PHP Code Browser
  • PHP Code Sniffer
  • PHP Copy/Paste Detector
  • PHP Mess Detector
  • PHPUnit

Read the rest over at Mike Willbanks blog.

Getting Started with Zend_Test

Matthew Turland has written a very nice article on Unit Testing using Zend_Test, Zend_Test_PHPUnit_DatabaseTestCase, Zend_Test_PHPUnit_ControllerTestCase where he uses a few interesting solutions. Definitely worth a read.

“I worked on a project recently where we used Zend Framework. As part of that project, I was tasked with writing unit tests. So, I went to the “tests” directory generated for me by the zf CLI utility to get started…”

via Getting Started with Zend_Test | Blue Parabola, LLC.

Continuous Integration for PHP – phpUnderControl & CruiseControl

Did you know that you can automate unit tests (which is the PHP worlds equalient of compilation checks 🙂 ).

Set up your development team using local checkouts of the project and have them do local PHPUnit tests, check their changes in and then get Continuous Integration checks done on a central server using phpUnderControl that emails the team with success/fail reports, it’s a good way to work.

phpUnderControl is an addon application for the continuous integration tool CruiseControl, which integrates some of the best PHP development tools. This project aims to make your first steps with CruiseControl and PHP as easy as possible. Therefore phpUnderControl comes with a command line tool that performs all modifications to an existing CruiseControl installation.

Integrated tools

  • Testing and software metrics – PHPUnit is the most popular xUnit implementation for PHP that provides a framework for automated software tests. Except the pure test automation PHPUnit contains a rich set of features like Code Coverage, Project Mess Detection and Software Metrics. To visualize the generated XML reports phpUnderControl comes with a set of XSL stylesheets that prepare the output for CruiseControl.
  • Documentation – phpUnderControl uses the most common documentation tool for PHP projects, PhpDocumentor, to generate an up to date documentation of the software on every build cycle. Therefore the developers will always get the latest API documentation of their project. Additionally phpUnderControl extracts the documentation violations found by the PhpDocumentor and visualizes these as an additional quality report in the user interface and the project time line of documentation violations.
  • Coding Standards – With the package PHP_CodeSniffer the PEAR project gave PHP developers a very useful tool to detect coding standard violations in a project. Since version 1.0.0RC3 it has native support for the Checkstyle XML format that can be visualized by CruiseControl. PHP_CodeSniffer comes with a variety of pre defined coding standards like PEAR and ZEND but due to its modular structure you can easily implement a custom rule set or extend one of the pre defined sets. This development tool assures that the whole project code will remain clean and consistent.

Go and check it out today 🙂