Skip to content

Commit 3d3a6f7

Browse files
committed
test: add test for null format
1 parent cbfee82 commit 3d3a6f7

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Test/WebTestCaseTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function testAssertResponseFormat()
8484

8585
$this->getResponseTester(new Response('', 200, ['Content-Type' => 'application/vnd.myformat']))->assertResponseFormatSame('custom');
8686
$this->getResponseTester(new Response('', 200, ['Content-Type' => 'application/ld+json']))->assertResponseFormatSame('jsonld');
87+
$this->getResponseTester(new Response())->assertResponseFormatSame(null);
8788
$this->expectException(AssertionFailedError::class);
8889
$this->expectExceptionMessage("Failed asserting that the Response format is jsonld.\nHTTP/1.0 200 OK");
8990
$this->getResponseTester(new Response())->assertResponseFormatSame('jsonld');

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class ResponseFormatSame extends Constraint
2525
private $request;
2626
private $format;
2727

28-
public function __construct(Request $request, string $format)
28+
public function __construct(Request $request, ?string $format)
2929
{
3030
$this->request = $request;
3131
$this->format = $format;
@@ -36,7 +36,7 @@ public function __construct(Request $request, string $format)
3636
*/
3737
public function toString(): string
3838
{
39-
return 'format is '.$this->format;
39+
return 'format is '.($this->format ?? 'null');
4040
}
4141

4242
/**

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,20 @@ public function testConstraint()
4242

4343
$this->fail();
4444
}
45+
46+
public function testNullFormat()
47+
{
48+
$constraint = new ResponseFormatSame(new Request(), null);
49+
$this->assertTrue($constraint->evaluate(new Response(), '', true));
50+
51+
try {
52+
$constraint->evaluate(new Response('', 200, ['Content-Type' => 'application/ld+json']));
53+
} catch (ExpectationFailedException $e) {
54+
$this->assertStringContainsString("Failed asserting that the Response format is null.\nHTTP/1.0 200 OK", TestFailure::exceptionToString($e));
55+
56+
return;
57+
}
58+
59+
$this->fail();
60+
}
4561
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy