-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathApiProblemExceptionTransformerTest.php
More file actions
58 lines (47 loc) · 1.83 KB
/
ApiProblemExceptionTransformerTest.php
File metadata and controls
58 lines (47 loc) · 1.83 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
<?php
declare(strict_types=1);
namespace PhproTest\ApiProblemBundle\Transformer;
use Exception;
use Phpro\ApiProblem\ApiProblemInterface;
use Phpro\ApiProblem\Exception\ApiProblemException;
use Phpro\ApiProblemBundle\Transformer\ApiProblemExceptionTransformer;
use Phpro\ApiProblemBundle\Transformer\ExceptionTransformerInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
#[CoversClass(ApiProblemExceptionTransformer::class)]
class ApiProblemExceptionTransformerTest extends TestCase
{
use ProphecyTrait;
/**
* @var ApiProblemInterface|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(ApiProblemInterface::class);
$this->apiProblem->toArray()->willReturn([]);
}
#[Test]
public function it_is_an_exception_transformer(): void
{
$transformer = new ApiProblemExceptionTransformer();
$this->assertInstanceOf(ExceptionTransformerInterface::class, $transformer);
}
#[Test]
public function it_accepts_api_problem_exceptions(): void
{
$transformer = new ApiProblemExceptionTransformer();
$this->assertTrue($transformer->accepts(new ApiProblemException($this->apiProblem->reveal())));
$this->assertFalse($transformer->accepts(new Exception()));
}
#[Test]
public function it_transforms_exception_to_api_problem(): void
{
$transformer = new ApiProblemExceptionTransformer();
$apiProblem = $this->apiProblem->reveal();
$this->assertSame($apiProblem, $transformer->transform(new ApiProblemException($apiProblem)));
}
}