Zend Framework

Zend Framework 1.7 + Zend Studio 6.1 + PHPUnit

With the new release of Zend Framework 1.7 , like many others, I was eager to download it and give it a whirl. Now I’m currently developing a ZF web app and we’re still in the early stages so I upgraded our trunk version of ZF to 1.7 and re-ran all my PHPUnit test cases using Zend Studio. To no suprise there was a slight problem:

Debug Error: /foo/library/Zend/Test/PHPUnit/ControllerTestCase.php line 1099 – Call to undefined method FooControllerTest::incrementAssertionCounter()

Now I did manage to track down exactly what the issue is. I won’t go into details about how but I’ll just say this: Zend Debugger is a god send for debugging PHP applications (and in this case a PHP test suite).

Anywho, basically with the release of ZF 1.7, Zend_Test_PHPUnit_ControllerTestCase::_incrementAssertionCounter() was added and is called by every Zend_Test_PHPUnit_ControllerTestCase::assertBlah(…) function. It simply does a PHPUnit version check and loops through to PHPUnit and calls either PHPUnit_Framework_TestCase::incrementAssertionCounter() if your PHPUnit version < 3.3.0 or PHPUnit_Framework_TestCase::addToAssertionCounter(1) if your PHPUnit version >= 3.3.0.

The problem is this, PHPUnit did not add PHPUnit_Framework_TestCase::incrementAssertionCounter() until version 3.3.0. Hence if you have a version of PHPUnit < 3.3.0, ZF 1.7 is not compatible 😦 This is true for all Zend Studio 6.1 users as it ships with PHPUnit v3.2.18. Why did the ZF devs not add a check to make sure the version was above 3.3.0 is beyond me. This breaks ZF 1.7 backwards compatibility with ZF 1.6 as this “increment/add to assertion counter” was not even present in ZF 1.6.

Now here’s the temporary solution: Since you can’t change the PHPUnit location in Zend Studio, you have to patch your Zend Studio install with an updated PHPUnit library. At the time of this writing the latest was 3.3.4. Grab it from PEAR and do the following:

  1. Navigate to your ${ZEND_STUDIO_INSTALL_DIR}/plugins/com.zend.php.phpunit_6.1.0.v20080907/resources/library directory.
  2. Rename PHPUnit to PHPUnit-3.2.18
  3. Move the PHPUnit v3.3.4 folder you got from PEAR into the same directory and make sure it’s named PHPUnit

Now your PHPUnit test cases should happily run in Zend Studio 😀

I’m going to take this issue up with the ZF devs and hopefully they’ll be a bugfix in 1.7.1 but who knows. Just wanted to help anyone who may be experiencing the same problem.

Advertisements