Skip to content

Commit

Permalink
[DX] Enhance step response header "foo" should have value "chuck" r…
Browse files Browse the repository at this point in the history
…eadability on failing
  • Loading branch information
Guillaume MOREL committed Aug 14, 2015
1 parent 913b773 commit aaab30d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/RestApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,19 @@ public function theResponseCodeShouldBe($code)
*/
public function theResponseHeaderShouldHave($headerKey, $expectedValue)
{
if (! $this->response->getHeader($headerKey)->hasValue($expectedValue)) {
throw new \mageekguy\atoum\asserter\exception($this->asserter, sprintf('Header "%s" is not containing "%s" in last response.', $headerKey, $expectedValue));
}
$hasValue = $this->response->getHeader($headerKey)->hasValue($expectedValue);
$this->asserter->boolean($hasValue)
->isTrue(
sprintf(
'Header "%s" is not containing in last response:
"%s"
Received:
"%s"',
$headerKey,
$expectedValue,
implode(', ', $this->response->getHeader($headerKey)->toArray())
)
);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/Units/RestApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ function() use($sut) {
$sut->theResponseHeaderShouldHave('foo', 'chuck');
}
)->isInstanceOf('\mageekguy\atoum\asserter\exception')
->hasMessage('Header "foo" is not containing in last response:
"chuck"
Received:
"bar, azerty"
-Expected
+Actual
@@ -1 +1 @@
-bool(true)
+bool(false)')
;
}

Expand Down

0 comments on commit aaab30d

Please sign in to comment.