Skip to content

Commit 621b10e

Browse files
committed
Constraint ResponseHeaderSame now shows the actual header value
1 parent 0383b06 commit 621b10e

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseHeaderSame.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ final class ResponseHeaderSame extends Constraint
1818
{
1919
private string $headerName;
2020
private string $expectedValue;
21+
private ?string $actualValue = null;
2122

2223
public function __construct(string $headerName, string $expectedValue)
2324
{
@@ -27,16 +28,23 @@ public function __construct(string $headerName, string $expectedValue)
2728

2829
public function toString(): string
2930
{
30-
return sprintf('has header "%s" with value "%s"', $this->headerName, $this->expectedValue);
31+
$output = sprintf('has header "%s" with value "%s"', $this->headerName, $this->expectedValue);
32+
33+
if (null !== $this->actualValue) {
34+
$output .= sprintf(', value of header "%s" is "%s"', $this->headerName, $this->actualValue);
35+
}
36+
37+
return $output;
3138
}
3239

3340
/**
3441
* @param Response $response
3542
*/
3643
protected function matches($response): bool
3744
{
38-
return $this->expectedValue === $response->headers->get($this->headerName, null);
39-
}
45+
$this->actualValue = $response->headers->get($this->headerName, null);
46+
47+
return $this->expectedValue === $this->actualValue;}
4048

4149
/**
4250
* @param Response $response

src/Symfony/Component/HttpFoundation/Tests/Test/Constraint/ResponseHeaderSameTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testConstraint()
2929
try {
3030
$constraint->evaluate(new Response());
3131
} catch (ExpectationFailedException $e) {
32-
$this->assertEquals("Failed asserting that the Response has header \"Cache-Control\" with value \"public\".\n", TestFailure::exceptionToString($e));
32+
$this->assertEquals("Failed asserting that the Response has header \"Cache-Control\" with value \"public\", value of header \"Cache-Control\" is \"no-cache, private\".\n", TestFailure::exceptionToString($e));
3333

3434
return;
3535
}

0 commit comments

Comments
 (0)