Skip to content

Commit cbe44ad

Browse files
committed
Add response code to cache hit/miss assertion message
1 parent ec53c67 commit cbe44ad

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/Test/PHPUnit/AbstractCacheConstraint.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ protected function matches($other)
6262
*/
6363
protected function failureDescription($other)
6464
{
65-
return 'the responses are identical';
65+
return sprintf(
66+
'response (with status code %s) %s',
67+
$other->getStatusCode(),
68+
$this->toString()
69+
);
6670
}
6771
}

tests/Unit/Test/PHPUnit/AbstractCacheConstraintTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ abstract class AbstractCacheConstraintTest extends \PHPUnit_Framework_TestCase
77
protected function getResponseMock()
88
{
99
$mock = \Mockery::mock(
10-
'\Psr\Http\Message\ResponseInterface[hasHeader,getHeaderLine]'
10+
'\Psr\Http\Message\ResponseInterface[hasHeader,getHeaderLine,getStatusCode]'
1111
);
12-
12+
1313
return $mock;
1414
}
1515
}

tests/Unit/Test/PHPUnit/IsCacheHitConstraintTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ public function setUp()
2727

2828
/**
2929
* @expectedException \PHPUnit_Framework_ExpectationFailedException
30+
* @expectedExceptionMessage Failed asserting that response (with status code 500) is a cache hit
3031
*/
3132
public function testMatches()
3233
{
3334
$response = $this->getResponseMock()
3435
->shouldReceive('hasHeader')->with('cache-header')->andReturn(true)
3536
->shouldReceive('getHeaderLine')->with('cache-header')->once()->andReturn('MISS')
37+
->shouldReceive('getStatusCode')->andReturn(500)
3638
->getMock();
3739

3840
$this->constraint->evaluate($response);

tests/Unit/Test/PHPUnit/IsCacheMissConstraintTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ public function setUp()
2727

2828
/**
2929
* @expectedException \PHPUnit_Framework_ExpectationFailedException
30+
* @expectedExceptionMessage Failed asserting that response (with status code 200) is a cache miss
3031
*/
3132
public function testMatches()
3233
{
3334
$response = $this->getResponseMock()
3435
->shouldReceive('hasHeader')->with('cache-header')->andReturn(true)
35-
->shouldReceive('getHeaderLine')->with('cache-header')->once()
36-
->andReturn('HIT')
36+
->shouldReceive('getHeaderLine')->with('cache-header')->once()->andReturn('HIT')
37+
->shouldReceive('getStatusCode')->andReturn(200)
3738
->getMock();
3839

3940
$this->constraint->evaluate($response);

0 commit comments

Comments
 (0)