|
19 | 19 |
|
20 | 20 | class ResponseHeaderSameTest extends TestCase
|
21 | 21 | {
|
22 |
| - public function testConstraint() |
| 22 | + public function testResponseHeaderSameWithExpectedHeaderValueIsSame() |
23 | 23 | {
|
24 |
| - $constraint = new ResponseHeaderSame('Cache-Control', 'no-cache, private'); |
25 |
| - $this->assertTrue($constraint->evaluate(new Response(), '', true)); |
26 |
| - $constraint = new ResponseHeaderSame('Cache-Control', 'public'); |
27 |
| - $this->assertFalse($constraint->evaluate(new Response(), '', true)); |
| 24 | + $constraint = new ResponseHeaderSame('X-Token', 'custom-token'); |
| 25 | + |
| 26 | + $response = new Response(); |
| 27 | + $response->headers->set('X-Token', 'custom-token'); |
| 28 | + |
| 29 | + $this->assertTrue($constraint->evaluate($response, '', true)); |
| 30 | + } |
| 31 | + |
| 32 | + public function testResponseHeaderSameWithExpectedHeaderValueIsDifferent() |
| 33 | + { |
| 34 | + $constraint = new ResponseHeaderSame('X-Token', 'custom-token'); |
| 35 | + |
| 36 | + $response = new Response(); |
| 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 | + public function testResponseHeaderSameWithExpectedHeaderIsNotPresent() |
| 53 | + { |
| 54 | + $constraint = new ResponseHeaderSame('X-Token', 'custom-token'); |
| 55 | + |
| 56 | + $response = new Response(); |
| 57 | + |
| 58 | + $this->assertFalse($constraint->evaluate($response, '', true)); |
28 | 59 |
|
29 | 60 | try {
|
30 |
| - $constraint->evaluate(new Response()); |
| 61 | + $constraint->evaluate($response); |
31 | 62 | } 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)); |
33 | 64 |
|
34 | 65 | return;
|
35 | 66 | }
|
|
0 commit comments