Phing Zend Framework and PHPUnit

Steve Popoola —  May 1, 2012 — 3 Comments

I have been scratching my head trying to resolve the issues arising from implementing a Continuous Integration setup for a Zend Framework project using Phing and PHPUnit.

What should have been a straight forward exercise turned into a head scratching one and after hours of visiting the PHPUnit and Phing manual, I did not have an answer to the problem. Then I saw a bug entered on the Zend Framework Issue Tracker and there it was!

First, PHPUnit 3.6  changed it’s implementation of the evaluate method in PHPUnit_Framework_Constraint.  This meant that the same method in Zend_Test_PHPUnit_Constraint_DomQuery was no longer compatible therefore making it impossible to run tests for  projects running Zend Framework 1.11.

The folks at Zend were not ready to fix this issue as they are currently working towards the release of  the Zend Framework 2. It therefore meant that the other option was for me to install PHPUnit 3.4 which is the ZF supported version.

I had two options, one was to run multiple versions of phpunit  but I chose to downgrade as follow

sudo pear uninstall phpunit/PHPUnit
sudo pear uninstall phpunit/DbUnit
sudo pear uninstall phpunit/PHP_CodeCoverage
sudo pear uninstall phpunit/File_Iterator
sudo pear uninstall phpunit/Text_Template
sudo pear uninstall phpunit/PHP_Timer
sudo pear uninstall phpunit/PHPUnit_MockObject
sudo pear uninstall phpunit/PHPUnit_Selenium
sudo pear uninstall pear.symfony-project.com/YAML

I manually downloaded the PHPUnit-3.4 source and copied it to /usr/share.PHPUnit

Finally,  I copied the phpunit.php file to /usr/bin/phpunit

phpunit –version
PHPUnit 3.4.15 by Sebastian Bergmann

When I ran Phing, again I got another error. The phpunit PhingTask required phpunit >= 3.6.0. What??

Another head scratching exercise.  How did I solve this?

I modified the build file and changed the phpunit task to an exec task and passed the command line parameters.

Voila!

steve@steve-desktop:/var/www/ciproject$ phing

Buildfile: /var/www/ciproject/build.xml

ciproject > phpunit:

[echo] phpunit test start

[echo] phpunit test end

BUILD FINISHED

Total time: 0.1633 seconds

Note: Remember to set  the attributes passthru=”true” and set dir=”tests”  or else you will have include errors to grapple with.

Thanks for reading.

Steve Popoola

Posts Google+

3 responses to Phing Zend Framework and PHPUnit

  1. Clearing the Pear Cache helps, also in summary:

    a) Text_Template has to be unliatsnled before Mock_Object which it depends on

    b) Token_Stream also has to be unliatsnled as version 1.0.1 has to be installed before Code_Coverage which installs 1.1.1 as Scott put it

    c) Text_Template has to be installed before Mock_Object which will install the 1.1.1

    The final command listing that worked for me is (I am on Windows so I just added sudo before pear for *nix):
    sudo pear uninstall phpunit/PHPUnit
    sudo pear uninstall phpunit/DbUnit
    sudo pear uninstall phpunit/PHP_CodeCoverage
    sudo pear uninstall phpunit/File_Iterator
    sudo pear uninstall phpunit/PHP_Timer
    sudo pear uninstall phpunit/PHPUnit_MockObject
    sudo pear uninstall phpunit/Text_Template
    sudo pear uninstall phpunit/PHPUnit_Selenium
    sudo pear uninstall pear.symfony-project.com/YAML
    sudo pear uninstall phpunit/PHP_TokenStream
    sudo pear clear-cachesudo pear install pear.symfony-project.com/YAML-1.0.2
    sudo pear install phpunit/PHPUnit_Selenium-1.0.1
    sudo pear install phpunit/Text_Template-1.0.0
    sudo pear install phpunit/PHPUnit_MockObject-1.0.3
    sudo pear install phpunit/PHP_Timer-1.0.0
    sudo pear install phpunit/File_Iterator-1.2.3
    sudo pear install phpunit/PHP_TokenStream-1.0.1
    sudo pear install phpunit/PHP_CodeCoverage-1.0.2
    sudo pear install phpunit/DbUnit-1.0.0
    sudo pear install phpunit/PHPUnit-3.5.15

  2. Thanks Muhsin, it is indeed important to make sure that the dependencies are installed in specific order.

Leave a Reply

*

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>