Skip to content

Commit 18c8190

Browse files
committed
add assertHeaderContain() method for asserts that the response contains the given header and contains the optional value.
1 parent 30a10d4 commit 18c8190

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Testing/Base/ResponseAssertTrait.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@ public function assertHeader($headerName, $value = null)
6363
return $this;
6464
}
6565

66+
/**
67+
* Asserts that the response contains the given header and contains the optional value.
68+
*
69+
* @param string $headerName
70+
* @param mixed $value
71+
* @return $this
72+
* @throws \PHPUnit_Framework_AssertionFailedError
73+
*/
74+
public function assertHeaderContain($headerName, $value = null)
75+
{
76+
PHPUnit::assertTrue($this->hasHeader($headerName), "Header [{$headerName}] not present on response.");
77+
78+
$actual = $this->getHeaderLine($headerName);
79+
80+
if (null !== $value) {
81+
PHPUnit::assertContains($value, $this->getHeaderLine($headerName), "Header [{$headerName}] was found, but value [{$actual}] does not contain [{$value}].");
82+
}
83+
84+
return $this;
85+
}
86+
6687
/**
6788
* Assert that the given string is contained within the response.
6889
*

0 commit comments

Comments
 (0)