-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathErrorHandlerFactoryTest.php
More file actions
71 lines (60 loc) · 2.15 KB
/
ErrorHandlerFactoryTest.php
File metadata and controls
71 lines (60 loc) · 2.15 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
<?php
declare(strict_types=1);
namespace DotTest\ErrorHandler;
use Dot\ErrorHandler\ErrorHandler;
use Dot\ErrorHandler\ErrorHandlerFactory;
use Mezzio\Middleware\ErrorResponseGenerator;
use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
class ErrorHandlerFactoryTest extends TestCase
{
private ContainerInterface|MockObject $container;
/** @var callable $responseFactory */
private $responseFactory;
/**
* @throws Exception
*/
public function setUp(): void
{
$this->container = $this->createMock(ContainerInterface::class);
$this->responseFactory = fn(): ResponseInterface => $this->createMock(ResponseInterface::class);
}
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function testWillCreateWithDefaultOption(): void
{
$this->container->method('has')
->with(ErrorResponseGenerator::class)
->willReturn(false);
$this->container->method('get')
->with(ResponseInterface::class)
->willReturn($this->responseFactory);
$result = (new ErrorHandlerFactory())($this->container);
$this->assertInstanceOf(ErrorHandler::class, $result);
}
/**
* @throws ContainerExceptionInterface
* @throws Exception
* @throws NotFoundExceptionInterface
*/
public function testWillCreateWithErrorResponseGenerator(): void
{
$this->container->method('has')
->with(ErrorResponseGenerator::class)
->willReturn(true);
$this->container->method('get')
->willReturnMap([
[ErrorResponseGenerator::class, $this->createMock(ErrorResponseGenerator::class)],
[ResponseInterface::class, $this->responseFactory],
]);
$result = (new ErrorHandlerFactory())($this->container);
$this->assertInstanceOf(ErrorHandler::class, $result);
}
}