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

4 thoughts on “Zend Framework 1.7 + Zend Studio 6.1 + PHPUnit

  1. Thanks bunches! Now I no longer have to maintain hacks to get Zend to work w/ the same tests that work flawlessly w/ my build server’s PHPUnit 3.3!!

    Why did they release ZS 6.1 with 3.2 when 3.3 was already out?

  2. How surprising we are on Zend Studio 7.1.2 and YOU STILL have to use this work around. There is no way in the preferences to change the path to where the PHPUnit library resides. What a pain in the ass 😦 You would think that in a year they could have that bug fixed… I guess not!!! Cmon ZEND!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s