Passed
Push — master ( 035a69...ef3bdc )
by Kirill
03:22
created

InterceptableCoreTest::testNoInterceptors2()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 0
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\Core;
13
14
use PHPUnit\Framework\TestCase;
15
use Spiral\Core\Container;
16
use Spiral\Core\Exception\InterceptorException;
17
use Spiral\Core\InterceptableCore;
18
use Spiral\Core\InterceptorPipeline;
19
use Spiral\Tests\Core\Fixtures\DummyController;
20
use Spiral\Tests\Core\Fixtures\SampleCore;
21
22
class InterceptableCoreTest extends TestCase
23
{
24
    public function testNoInterceptors(): void
25
    {
26
        $core = new SampleCore(new Container());
27
        $int = new InterceptableCore($core);
28
29
        $this->assertSame('Hello, Antony.', $int->callAction(
30
            DummyController::class,
31
            'index',
32
            ['name' => 'Antony']
33
        ));
34
    }
35
36
    public function testNoInterceptors2(): void
37
    {
38
        $core = new SampleCore(new Container());
39
        $int = new InterceptableCore($core);
40
        $int->addInterceptor(new DemoInterceptor());
41
42
        $this->assertSame('?Hello, Antony.!', $int->callAction(
43
            DummyController::class,
44
            'index',
45
            ['name' => 'Antony']
46
        ));
47
    }
48
49
    public function testNoInterceptors22(): void
50
    {
51
        $core = new SampleCore(new Container());
52
        $int = new InterceptableCore($core);
53
        $int->addInterceptor(new DemoInterceptor());
54
        $int->addInterceptor(new DemoInterceptor());
55
56
        $this->assertSame('??Hello, Antony.!!', $int->callAction(
57
            DummyController::class,
58
            'index',
59
            ['name' => 'Antony']
60
        ));
61
    }
62
63
    public function testInvalidPipeline(): void
64
    {
65
        $this->expectException(InterceptorException::class);
66
67
        $pipeline = new InterceptorPipeline();
68
        $pipeline->callAction(
69
            DummyController::class,
70
            'index',
71
            ['name' => 'Antony']
72
        );
73
    }
74
}
75