anonymous//tests/LazyHandlerTest.php$0   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 10
wmc 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Northwoods\Middleware;
5
6
use InvalidArgumentException;
7
use Northwoods\Middleware\Fixture\Handler;
8
use Nyholm\Psr7\ServerRequest;
9
use PHPUnit\Framework\TestCase;
10
use Psr\Container\ContainerInterface;
11
12
class LazyHandlerTest extends TestCase
13
{
14
    /** @var ContainerInterface */
15
    private $container;
16
17
    protected function setUp(): void
18
    {
19
        $this->container = new class implements ContainerInterface
20
        {
21
            public function has($id)
22
            {
23
                return class_exists($id);
24
            }
25
26
            public function get($id)
27
            {
28
                return new $id();
29
            }
30
        };
31
    }
32
33
    public function testDefersToHandlerImplementation(): void
34
    {
35
        $handler = new LazyHandler($this->container, Handler::class);
36
37
        $request = new ServerRequest('GET', 'https://example.com/');
38
39
        $response = $handler->handle($request);
40
41
        $this->assertEquals(400, $response->getStatusCode());
42
    }
43
44
    public function testFailsIfContainerDoesNotHaveHandler(): void
45
    {
46
        $this->expectException(InvalidArgumentException::class);
47
        $this->expectExceptionMessage('invalid');
48
49
        new LazyHandler($this->container, 'invalid');
50
    }
51
}
52