Zend Framework

ControllerTestCase broken with PHPUnit 3.3.3

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.7.0, 1.8.4
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Test_PHPUnit
  • Labels:
    None

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).

Activity

Hide
Matthew Weier O'Phinney added a comment -

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

Show
Matthew Weier O'Phinney added a comment - Fixed in r12372; now checks for PHPUnit version and calls appropriate method for that version.
Hide
Stefan Gehrig added a comment -

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(), '<=')) {
Show
Stefan Gehrig added a comment - 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(), '<=')) {
Hide
Stefan Gehrig added a comment -

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(), '<=')) {
Show
Stefan Gehrig added a comment - 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(), '<=')) {
Hide
Matthew Weier O'Phinney added a comment -

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.

Show
Matthew Weier O'Phinney added a comment - 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.
Hide
Stefan Gehrig added a comment -

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...

Show
Stefan Gehrig added a comment - 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...
Hide
Stefan Gehrig added a comment -

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!

Show
Stefan Gehrig added a comment - 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!
Hide
Matthew Weier O'Phinney added a comment -

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.

Show
Matthew Weier O'Phinney added a comment - 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.
Hide
Emil Ivanov added a comment -

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?

Show
Emil Ivanov added a comment - 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?
Hide
Matthew Weier O'Phinney added a comment -

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

Show
Matthew Weier O'Phinney added a comment - Sure. I'm reopening the issue so we can track that.
Hide
Matthew Weier O'Phinney added a comment -

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.

Show
Matthew Weier O'Phinney added a comment - 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.
Hide
Brian Hazzard added a comment -

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?

Show
Brian Hazzard added a comment - 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?
Hide
Brian Hazzard added a comment -

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

Show
Brian Hazzard added a comment - In the meantime "upgrading" to PHPUnit 3.3.16 does indeed fix this problem.
Hide
Ivan Bonilla Cortes added a comment -

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.

Show
Ivan Bonilla Cortes added a comment - 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.
Hide
Dolf Schimmel (Freeaqingme) added a comment -

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...

Show
Dolf Schimmel (Freeaqingme) added a comment - 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...
Hide
Lorna Mitchell added a comment -

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!)

Show
Lorna Mitchell added a comment - 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!)
Hide
Matthew Weier O'Phinney added a comment -

Fixed in trunk and 1.10 release branch.

Show
Matthew Weier O'Phinney added a comment - Fixed in trunk and 1.10 release branch.

People

Vote (1)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: