Passed
Push — master ( 3eb4db...99d5ff )
by Kirill
03:12
created

KernelTest.php$0 ➔ testDispatcher()   A

Complexity

Conditions 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 24
rs 9.536
cc 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A KernelTest.php$0 ➔ serve() 0 3 1
A KernelTest.php$0 ➔ canServe() 0 3 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Boot;
13
14
use PHPUnit\Framework\TestCase;
15
use Spiral\Boot\DispatcherInterface;
16
use Spiral\Boot\EnvironmentInterface;
17
use Spiral\Boot\Exception\BootException;
18
use Spiral\Tests\Boot\Fixtures\TestCore;
19
use Throwable;
20
21
class KernelTest extends TestCase
22
{
23
    /**
24
     *
25
     * @throws Throwable
26
     */
27
    public function testKernelException(): void
28
    {
29
        $this->expectException(BootException::class);
30
31
        $kernel = TestCore::init([
32
            'root' => __DIR__,
33
        ]);
34
35
        $kernel->serve();
36
    }
37
38
    /**
39
     * @throws Throwable
40
     */
41
    public function testDispatcher(): void
42
    {
43
        $kernel = TestCore::init([
44
            'root' => __DIR__,
45
        ]);
46
47
        $d = new class() implements DispatcherInterface {
48
            public $fired = false;
49
50
            public function canServe(): bool
51
            {
52
                return true;
53
            }
54
55
            public function serve(): void
56
            {
57
                $this->fired = true;
58
            }
59
        };
60
        $kernel->addDispatcher($d);
61
        $this->assertFalse($d->fired);
62
63
        $kernel->serve();
64
        $this->assertTrue($d->fired);
65
    }
66
67
    /**
68
     * @throws Throwable
69
     */
70
    public function testDispatcherReturnCode(): void
71
    {
72
        $kernel = TestCore::init([
73
            'root' => __DIR__,
74
        ]);
75
76
        $d = new class() implements DispatcherInterface {
77
            public function canServe(): bool
78
            {
79
                return true;
80
            }
81
82
            public function serve(): int
83
            {
84
                return 1;
85
            }
86
        };
87
        $kernel->addDispatcher($d);
88
89
        $result = $kernel->serve();
90
        $this->assertSame(1, $result);
91
    }
92
93
    /**
94
     * @throws Throwable
95
     */
96
    public function testEnv(): void
97
    {
98
        $kernel = TestCore::init([
99
            'root' => __DIR__,
100
        ]);
101
102
        $this->assertSame(
103
            'VALUE',
104
            $kernel->getContainer()->get(EnvironmentInterface::class)->get('INTERNAL')
105
        );
106
    }
107
}
108