Issues

ZF-4839: ControllerTestCase broken with PHPUnit 3.3.3

Description

Zend_Test_PHPUnit_ControllerTestCase is broken with PHPUnit 3.3.3 (most recent version) in revision 12333. ControllerTestCase uses {{PHPUnit_Framework_TestCase::incrementAssertionCounter()}} in line 1099, but this method is not available any more with PHPUnit 3.3.3 (don't know in which version this was removed). The appropriate method in PHPUnit 3.3.3 is {{PHPUnit_Framework_TestCase::addToAssertionCount($count)}}.

Comments

Fixed in r12372; now checks for PHPUnit version and calls appropriate method for that version.

Still not solved...

Line 1098 now reads


if (version_compare('3.3.3', PHPUnit_Runner_Version::id(), 'lt')) {

but must be


if (version_compare('3.3.3', PHPUnit_Runner_Version::id(), '<=')) {

Still not solved...

Line 1098 now reads


if (version_compare('3.3.3', PHPUnit_Runner_Version::id(), 'lt')) {

but must be


if (version_compare('3.3.3', PHPUnit_Runner_Version::id(), 'le')) {

or


if (version_compare('3.3.3', PHPUnit_Runner_Version::id(), '<=')) {

Um... no. We don't want <=, because at version 3.3.3 the change was introduced. Versions less than 3.3.3 require the handling as originally written.

Please see my comments in the following code:


/**
     * Increment assertion count
     * 
     * @return void
     */
    protected function _incrementAssertionCount()
    {
        $stack = debug_backtrace(); // why calling debug_backtrace() twice?
        foreach (debug_backtrace() as $step) {
            if (isset($step['object']) 
                && $step['object'] instanceof PHPUnit_Framework_TestCase
            ) {
                if (version_compare('3.3.3', PHPUnit_Runner_Version::id(), 'lt')) { // if 3.3.3 < CURRENT_VERSION do
                    $step['object']->addToAssertionCount(1);
                } else { // if 3.3.3 >= CURRENT_VERSION do
                    $step['object']->incrementAssertionCounter();
                }
                break;
            }
        }
    }

But in PHPUnit 3.3.3 {{incrementAssertionCounter()}} is not available any more...

Please see my comments in the following code:


/**
     * Increment assertion count
     * 
     * @return void
     */
    protected function _incrementAssertionCount()
    {
        $stack = debug_backtrace(); // why calling debug_backtrace() twice?
        foreach (debug_backtrace() as $step) {
            if (isset($step['object']) 
                && $step['object'] instanceof PHPUnit_Framework_TestCase
            ) {
                if (version_compare('3.3.3', PHPUnit_Runner_Version::id(), 'lt')) { // if 3.3.3 < CURRENT_VERSION do
                    $step['object']->addToAssertionCount(1);
                } else { // if 3.3.3 >= CURRENT_VERSION do
                    $step['object']->incrementAssertionCounter();
                }
                break;
            }
        }
    }

But in PHPUnit 3.3.3 {{incrementAssertionCounter()}} is not available any more...

Sorry to bother you with this!

I've rewritten it to the following:


if (version_compare(PHPUnit_Runner_Version::id(), '3.3.3', 'lt')) {
    $step['object']->incrementAssertionCounter();
} else {
    $step['object']->addToAssertionCount(1);
}

which should make the intention clearer.

We are running from an svn:externals of phpunit and it doesn't have a version there. Can this be some sort of other check, for example method_exists or something?

Sure. I'm reopening the issue so we can track that.

Changing to trivial and improvement, as it will work for most users of PHPUnit as-is right now; the improvement is for those tracking svn of PHPUnit.

I too have this issue. I tried changing the source code to the method_exists approach and had no luck. I also tried a hack-fix of defining incrementAssertionCounter in my test class and simply calling addToAssertionCount(1) in it's body... again, no luck. Has this been resolved?

In the meantime "upgrading" to PHPUnit 3.3.16 does indeed fix this problem.

This actually affects more users than those tracking svn of PHPUnit: Neither incrementAssertionCounter nor addtoAssertionCount exist on versions prior to 3.3.0 incrementAssertionCounter exists on versions 3.3.0 to 3.3.2 addtoAssertionCount exists on versions 3.3.3 and on

You may be wondering why someone would want to use an older version of phpunit. Sadly the latest version that ubuntu gnu/linux packages is 3.2.16: http://packages.ubuntu.com/jaunty/phpunit so this bug affects all ubuntu users that want to use a package manager.

As mentioned in the previous comment, somewhat older versions of PHPUnit don't have any of these methods for the simple reason that not all distributions are as keen on keeping everything cutting edge as others :'(

If there's no alternate solution in versions before 3.3.0 of PHPUnit, I suggest a following 'fix':


                if (version_compare(PHPUnit_Runner_Version::id(), '3.3.0', 'lt')) {
                    break; // Do nothing
                } elseif (version_compare(PHPUnit_Runner_Version::id(), '3.3.3', 'lt')) {
                    $step['object']->incrementAssertionCounter();
                } else {
                    $step['object']->addToAssertionCount(1);
                }
                break;

I'm setting the priority to major, as for there will certainly be many more people running distros like these...

I ran into this issue as well - using debian lenny, ZF 1.8 and the standard phpunit from apt-get which is 3.2.167. The patch from Dolf works perfectly for me (thanks!)

Fixed in trunk and 1.10 release branch.