|
23 | 23 | use Symfony\Component\HttpFoundation\Cookie as HttpFoundationCookie;
|
24 | 24 | use Symfony\Component\HttpFoundation\Request;
|
25 | 25 | use Symfony\Component\HttpFoundation\Response;
|
| 26 | +use Symfony\Component\HttpFoundation\Test\Constraint\ResponseFormatSame; |
26 | 27 |
|
27 | 28 | class WebTestCaseTest extends TestCase
|
28 | 29 | {
|
@@ -75,6 +76,20 @@ public function testAssertResponseRedirectsWithLocationAndStatusCode()
|
75 | 76 | $this->getResponseTester(new Response('', 302))->assertResponseRedirects('https://example.com/', 301);
|
76 | 77 | }
|
77 | 78 |
|
| 79 | + public function testAssertResponseFormat() |
| 80 | + { |
| 81 | + if (!class_exists(ResponseFormatSame::class)) { |
| 82 | + $this->markTestSkipped('Too old version of HttpFoundation.'); |
| 83 | + } |
| 84 | + |
| 85 | + $this->getResponseTester(new Response('', 200, ['Content-Type' => 'application/vnd.myformat']))->assertResponseFormatSame('custom'); |
| 86 | + $this->getResponseTester(new Response('', 200, ['Content-Type' => 'application/ld+json']))->assertResponseFormatSame('jsonld'); |
| 87 | + $this->getResponseTester(new Response())->assertResponseFormatSame(null); |
| 88 | + $this->expectException(AssertionFailedError::class); |
| 89 | + $this->expectExceptionMessage("Failed asserting that the Response format is jsonld.\nHTTP/1.0 200 OK"); |
| 90 | + $this->getResponseTester(new Response())->assertResponseFormatSame('jsonld'); |
| 91 | + } |
| 92 | + |
78 | 93 | public function testAssertResponseHasHeader()
|
79 | 94 | {
|
80 | 95 | $this->getResponseTester(new Response())->assertResponseHasHeader('Date');
|
@@ -284,6 +299,10 @@ private function getResponseTester(Response $response): WebTestCase
|
284 | 299 | $client = $this->createMock(KernelBrowser::class);
|
285 | 300 | $client->expects($this->any())->method('getResponse')->willReturn($response);
|
286 | 301 |
|
| 302 | + $request = new Request(); |
| 303 | + $request->setFormat('custom', ['application/vnd.myformat']); |
| 304 | + $client->expects($this->any())->method('getRequest')->willReturn($request); |
| 305 | + |
287 | 306 | return $this->getTester($client);
|
288 | 307 | }
|
289 | 308 |
|
|
0 commit comments