Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit29ae98d

Browse files
committed
Constraint ResponseHeaderSame now shows the actual header value
1 parent0383b06 commit29ae98d

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

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

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

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

2829
publicfunctiontoString():string
2930
{
30-
returnsprintf('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(', header "%s" is not set',$this->headerName);
35+
}
36+
37+
if (null !==$this->actualValue) {
38+
$output .=sprintf(', value of header "%s" is "%s"',$this->headerName,$this->actualValue);
39+
}
40+
41+
return$output;
3142
}
3243

3344
/**
3445
* @param Response $response
3546
*/
3647
protectedfunctionmatches($response):bool
3748
{
38-
return$this->expectedValue ===$response->headers->get($this->headerName,null);
49+
$this->actualValue =$response->headers->get($this->headerName,null);
50+
51+
return$this->expectedValue ===$this->actualValue;
3952
}
4053

4154
/**

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

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,48 @@
1919

2020
class ResponseHeaderSameTestextends TestCase
2121
{
22-
publicfunctiontestConstraint()
22+
publicfunctiontestResponseHeaderSameWithExpectedHeaderValueIsSame()
2323
{
24-
$constraint =newResponseHeaderSame('Cache-Control','no-cache, private');
25-
$this->assertTrue($constraint->evaluate(newResponse(),'',true));
26-
$constraint =newResponseHeaderSame('Cache-Control','public');
27-
$this->assertFalse($constraint->evaluate(newResponse(),'',true));
24+
$constraint =newResponseHeaderSame('X-Token','custom-token');
25+
26+
$response =newResponse();
27+
$response->headers->set('X-Token','custom-token');
28+
29+
$this->assertTrue($constraint->evaluate($response,'',true));
30+
}
31+
32+
publicfunctiontestResponseHeaderSameWithExpectedHeaderValueIsDifferent()
33+
{
34+
$constraint =newResponseHeaderSame('X-Token','custom-token');
35+
36+
$response =newResponse();
37+
$response->headers->set('X-Token','default-token');
38+
39+
$this->assertFalse($constraint->evaluate($response,'',true));
40+
41+
try {
42+
$constraint->evaluate($response);
43+
}catch (ExpectationFailedException$e) {
44+
$this->assertEquals("Failed asserting that the Response has header\"X-Token\" with value\"custom-token\", value of header\"X-Token\" is\"default-token\".\n", TestFailure::exceptionToString($e));
45+
46+
return;
47+
}
48+
49+
$this->fail();
50+
}
51+
52+
publicfunctiontestResponseHeaderSameWithExpectedHeaderIsNotPresent()
53+
{
54+
$constraint =newResponseHeaderSame('X-Token','custom-token');
55+
56+
$response =newResponse();
57+
58+
$this->assertFalse($constraint->evaluate($response,'',true));
2859

2960
try {
30-
$constraint->evaluate(newResponse());
61+
$constraint->evaluate($response);
3162
}catch (ExpectationFailedException$e) {
32-
$this->assertEquals("Failed asserting that the Response has header\"Cache-Control\" with value\"public\".\n", TestFailure::exceptionToString($e));
63+
$this->assertEquals("Failed asserting that the Response has header\"X-Token\" with value\"custom-token\", header\"X-Token\" is not set.\n", TestFailure::exceptionToString($e));
3364

3465
return;
3566
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp