Skip to content

Commit aff8abb

Browse files
committed
feature #43671 add ResponseIsUnprocessable (garak)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- add ResponseIsUnprocessable | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #40894 | License | MIT | Doc PR | none Commits ------- 61df7f1752 add ResponseIsUnprocessable
2 parents 2421d50 + 1abaf5d commit aff8abb

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\Test\Constraint;
13+
14+
use PHPUnit\Framework\Constraint\Constraint;
15+
use Symfony\Component\HttpFoundation\Response;
16+
17+
final class ResponseIsUnprocessable extends Constraint
18+
{
19+
/**
20+
* {@inheritdoc}
21+
*/
22+
public function toString(): string
23+
{
24+
return 'is unprocessable';
25+
}
26+
27+
/**
28+
* @param Response $other
29+
*
30+
* {@inheritdoc}
31+
*/
32+
protected function matches($other): bool
33+
{
34+
return Response::HTTP_UNPROCESSABLE_ENTITY === $other->getStatusCode();
35+
}
36+
37+
/**
38+
* @param Response $other
39+
*
40+
* {@inheritdoc}
41+
*/
42+
protected function failureDescription($other): string
43+
{
44+
return 'the Response '.$this->toString();
45+
}
46+
47+
/**
48+
* @param Response $other
49+
*
50+
* {@inheritdoc}
51+
*/
52+
protected function additionalFailureDescription($other): string
53+
{
54+
return (string) $other;
55+
}
56+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\Tests\Test\Constraint;
13+
14+
use PHPUnit\Framework\ExpectationFailedException;
15+
use PHPUnit\Framework\TestCase;
16+
use PHPUnit\Framework\TestFailure;
17+
use Symfony\Component\HttpFoundation\Response;
18+
use Symfony\Component\HttpFoundation\Test\Constraint\ResponseIsUnprocessable;
19+
20+
class ResponseIsUnprocessableTest extends TestCase
21+
{
22+
public function testConstraint()
23+
{
24+
$constraint = new ResponseIsUnprocessable();
25+
26+
$this->assertTrue($constraint->evaluate(new Response('', 422), '', true));
27+
$this->assertFalse($constraint->evaluate(new Response(), '', true));
28+
}
29+
}

0 commit comments

Comments
 (0)