ZF-11871: Zend_Test_PHPUnit_Constraint_Redirect is no longer compatible to PHPUnit_Framework_Constraint

Description

Hi,

since PHPUnit 3.6 it seems that Zend_Test is no longer completely compatible.

The methods "evaluate" and "fail" in class PHPUnit_Framework_Constraint changed amount, type and usage of their parameters. The class Zend_Test_PHPUnit_Constraint_Redirect doesn't override them correctly anymore.


public function evaluate($other, $assertType = null)
{
}
public function fail($other, $description, $not = false)
{
}

Should be:


public function evaluate($other, $assertType = null, $returnResult = false)
{
    //$returnResult needs to be implemented...
}
public function fail($other, $description, PHPUnit_Framework_ComparisonFailure $comparisonFailure = null)
{
    //$comparisonFailure needs to be implemented...
}

I hope this changes will get implemented into 1.11 branch, too, not only 2.0.

Thank you in advance and greetings, Rene

Comments

The supported branch of PHPUnit for Zend Framework v1 is v3.4.x. There are no plans to update ZFv1 to any newer version of PHPUnit.

On a side note, I've been using various releases of 3.5 without any obvious negative side-effects (beside the flood of deprecation notices). YMMV, though.

In the mean time, try sticking something like this in your Controller test case. It circumvents the evaluate() method that causes problems when testing Controller redirection or response codes.

/** * @param string $expectedCode * @param string $message */ public function assertResponseCode($expectedCode, $message = '') { $this->assertEquals($expectedCode, $this->getResponse()->getHttpResponseCode(), $message); }

/** * @param string $expectedUrl * @param string $message */ public function assertRedirectTo($expectedUrl, $message = '') { $headers = $this->getResponse()->getHeaders();

$actualUrl = '';

foreach($headers as $header) {
    if ($header['name'] === 'Location') {
        $actualUrl = $header['value'];
    }
}

$this->assertEquals($expectedUrl, $actualUrl, $message);

}