-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathApiProblemHttpExceptionTest.php
More file actions
80 lines (62 loc) · 2.43 KB
/
ApiProblemHttpExceptionTest.php
File metadata and controls
80 lines (62 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
declare(strict_types=1);
namespace PhproTest\ApiProblemBundle\Exception;
use Phpro\ApiProblem\Http\HttpApiProblem;
use Phpro\ApiProblemBundle\Exception\ApiProblemHttpException;
use Phpro\ApiProblemBundle\Transformer\ApiProblemExceptionTransformer;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Symfony\Component\HttpKernel\Exception\HttpException;
class ApiProblemHttpExceptionTest extends TestCase
{
use ProphecyTrait;
/**
* @var HttpApiProblem|ObjectProphecy
*/
private $apiProblem;
protected function setUp(): void/* The :void return type declaration that should be here would cause a BC issue */
{
$this->apiProblem = $this->prophesize(HttpApiProblem::class);
$this->apiProblem->toArray()->willReturn([]);
}
#[Test]
public function it_is_accepted_by_the__api_problem_exception_transformer(): void
{
$transformer = new ApiProblemExceptionTransformer();
$this->assertTrue($transformer->accepts(new ApiProblemHttpException($this->apiProblem->reveal())));
}
#[Test]
public function it_is_an_instance_of__http_exception(): void
{
$exception = new ApiProblemHttpException($this->apiProblem->reveal());
$this->assertInstanceOf(HttpException::class, $exception);
}
#[Test]
public function it_contains_an_api_problem(): void
{
$apiProblem = $this->apiProblem->reveal();
$exception = new ApiProblemHttpException($apiProblem);
$this->assertEquals($apiProblem, $exception->getApiProblem());
}
#[Test]
public function it_returns_the_correct_http_headers(): void
{
$exception = new ApiProblemHttpException($this->apiProblem->reveal());
$this->assertEquals(['Content-Type' => 'application/problem+json'], $exception->getHeaders());
}
#[Test]
public function it_returns_the_correct_default_http_statuscode(): void
{
$exception = new ApiProblemHttpException($this->apiProblem->reveal());
$this->assertEquals(400, $exception->getStatusCode());
}
#[Test]
public function it_returns_the_correct_specified_http_statuscode(): void
{
$this->apiProblem->toArray()->willReturn(['status' => 401]);
$exception = new ApiProblemHttpException($this->apiProblem->reveal());
$this->assertEquals(401, $exception->getStatusCode());
}
}