You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7556
User: @sebastianbergmann
Created On: 2015-05-29T11:41:12Z
Updated At: 2015-11-06T21:55:09Z
Body AbstractControllerTestCase::assertResponseStatusCode() is not counted as an assertion in the failure case. This is due to the fact that an PHPUnit_Framework_ExpectationFailedException is thrown when the actual and expected response status code are not equal:
publicfunctionassertResponseStatusCode($code)
{
if ($this->useConsoleRequest) {
if (!in_array($code, array(0, 1))) {
thrownewPHPUnit_Framework_ExpectationFailedException(
'Console status code assert value must be O (valid) or 1 (error)'
);
}
}
$match = $this->getResponseStatusCode();
if ($code != $match) {
thrownewPHPUnit_Framework_ExpectationFailedException(
sprintf('Failed asserting response code "%s", actual status code is "%s"', $code, $match)
);
}
$this->assertEquals($code, $match);
}
Since the comparison of actual and expected response status code is not performed using assertEquals() or assertThat(), for instance, the assertion counter is not incremented.
The first place in the method's code where a PHPUnit_Framework_ExpectationFailedException is thrown could be refactored as
$this->assertThat(
$code,
$this->logicalOr(
$this->equalTo(0),
$this->equalTo(1)
),
'Console status code assert value must be O (valid) or 1 (error)'
);
It is not as easy as this, unfortunately, for the second place in the code where a PHPUnit_Framework_ExpectationFailedException is thrown:
if ($code != $match) {
thrownewPHPUnit_Framework_ExpectationFailedException(
sprintf('Failed asserting response code "%s", actual status code is "%s"', $code, $match)
);
}
$this->assertEquals($code, $match);
When the actual and expected response status codes are not equal then a custom message is generated and used with the manually thrown PHPUnit_Framework_ExpectationFailedException. This, again, circumvents the assertion counter.
When the actual and expected response status codes are equal then assertEquals() is used to verify the match again. This ensures that the assertion is counted in the success case.
The assertion methods of AbstractControllerTestCase should be refactored to follow the best practice of implementing custom assertions for PHPUnit. Simply implement a constraint object (by extending PHPUnit_Framework_Constraint) for each assertion. Then refactor the assertion to use the constraint object by passing it to assertThat().
The text was updated successfully, but these errors were encountered:
This issue has been moved from the
zendframework
repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.htmlOriginal Issue: https://api.github.com/repos/zendframework/zendframework/issues/7556
User: @sebastianbergmann
Created On: 2015-05-29T11:41:12Z
Updated At: 2015-11-06T21:55:09Z
Body
AbstractControllerTestCase::assertResponseStatusCode()
is not counted as an assertion in the failure case. This is due to the fact that anPHPUnit_Framework_ExpectationFailedException
is thrown when the actual and expected response status code are not equal:Since the comparison of actual and expected response status code is not performed using
assertEquals()
orassertThat()
, for instance, the assertion counter is not incremented.The first place in the method's code where a
PHPUnit_Framework_ExpectationFailedException
is thrown could be refactored asIt is not as easy as this, unfortunately, for the second place in the code where a
PHPUnit_Framework_ExpectationFailedException
is thrown:When the actual and expected response status codes are not equal then a custom message is generated and used with the manually thrown
PHPUnit_Framework_ExpectationFailedException
. This, again, circumvents the assertion counter.When the actual and expected response status codes are equal then
assertEquals()
is used to verify the match again. This ensures that the assertion is counted in the success case.The assertion methods of
AbstractControllerTestCase
should be refactored to follow the best practice of implementing custom assertions for PHPUnit. Simply implement a constraint object (by extendingPHPUnit_Framework_Constraint
) for each assertion. Then refactor the assertion to use the constraint object by passing it toassertThat()
.The text was updated successfully, but these errors were encountered: