RouterBindingTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 28
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_inject_controller_with_request_dependency() 0 12 1
A test_inject_dependencies_in_controllers() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Feature\Router;
6
7
use Gacela\Router\Configure\Bindings;
8
use Gacela\Router\Configure\Routes;
9
use Gacela\Router\Entities\Request;
10
use Gacela\Router\Router;
11
use GacelaTest\Feature\Router\Fake\Name;
12
use GacelaTest\Feature\Router\Fake\NameInterface;
13
use GacelaTest\Feature\Router\Fixtures\FakeControllerWithDependencies;
14
use GacelaTest\Feature\Router\Fixtures\FakeControllerWithRequest;
15
use PHPUnit\Framework\TestCase;
16
17
final class RouterBindingTest extends TestCase
18
{
19
    public function test_inject_dependencies_in_controllers(): void
20
    {
21
        $_SERVER['REQUEST_URI'] = 'https://example.org/expected/uri';
22
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
23
24
        $this->expectOutputString('default-Expected!');
25
26
        $router = new Router(static function (Bindings $binding, Routes $routes): void {
27
            $routes->get('expected/uri', FakeControllerWithDependencies::class);
28
            $binding->bind(NameInterface::class, new Name('Expected!'));
29
        });
30
        $router->run();
31
    }
32
33
    public function test_inject_controller_with_request_dependency(): void
34
    {
35
        $_SERVER['REQUEST_URI'] = 'https://example.org/expected';
36
        $_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
37
        $_GET['name'] = 'Katarn';
38
39
        $this->expectOutputString('Katarn');
40
41
        $router = new Router(static function (Routes $routes): void {
42
            $routes->get('expected', FakeControllerWithRequest::class);
43
        });
44
        $router->run();
45
    }
46
}
47