Passed
Push — master ( da738a...72a485 )
by Woody
40s
created

anonymous//tests/LazyHandlerTest.php$0   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 10
c 0
b 0
f 0
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;
0 ignored issues
show
Coding Style introduced by
Private member variable "container" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
16
17
    public function setUp()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
18
    {
19
        $this->container = new class implements ContainerInterface
20
        {
21
            public function has($id)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
22
            {
23
                return class_exists($id);
24
            }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
25
26
            public function get($id)
27
            {
28
                return new $id();
29
            }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
30
        };
31
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
32
33
    public function testVerifiesHandlerImplementation(): void
34
    {
35
        $this->expectException(InvalidArgumentException::class);
36
        $this->expectExceptionMessage(self::class);
37
38
        $handler = new LazyHandler($this->container, self::class);
0 ignored issues
show
Unused Code introduced by
The assignment to $handler is dead and can be removed.
Loading history...
39
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
40
41
    public function testDefersToHandlerImplemention(): void
42
    {
43
        $handler = new LazyHandler($this->container, Handler::class);
44
45
        $request = new ServerRequest('GET', 'https://example.com/');
46
47
        $response = $handler->handle($request);
48
49
        $this->assertEquals(400, $response->getStatusCode());
50
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
51
}
52