Passed
Pull Request — master (#439)
by Kirill
06:35
created

PipelineInterceptorTest::testMixAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Tests\Framework\Interceptor;
6
7
use Spiral\Tests\Framework\HttpTest;
8
9
class PipelineInterceptorTest extends HttpTest
10
{
11
    public function testWithoutPipeline(): void
12
    {
13
        $response = $this->get('/intercepted/without')->getBody();
14
        $output = json_decode((string)$response, true);
15
        //appends are executed after the sub-core action called: one->two->three->action[without]->[three]->[two]->[one]
16
        $this->assertSame(['without', 'three', 'two', 'one'], $output);
17
    }
18
19
    public function testWith(): void
20
    {
21
        $response = $this->get('/intercepted/with')->getBody();
22
        $output = json_decode((string)$response, true);
23
        $this->assertSame(['with', 'three', 'two', 'one'], $output);
24
    }
25
26
    public function testMix(): void
27
    {
28
        $response = $this->get('/intercepted/mix')->getBody();
29
        $output = json_decode((string)$response, true);
30
        //pipeline interceptors are injected into the middle
31
        $this->assertSame(['mix', 'six', 'three', 'two', 'one', 'five', 'four'], $output);
32
    }
33
34
    public function testDup(): void
35
    {
36
        $response = $this->get('/intercepted/dup')->getBody();
37
        $output = json_decode((string)$response, true);
38
        //pipeline interceptors are added to the end
39
        $this->assertSame(['dup', 'three', 'two', 'one', 'three', 'two', 'one'], $output);
40
    }
41
42
    public function testSkipNext(): void
43
    {
44
        $response = $this->get('/intercepted/skip')->getBody();
45
        $output = json_decode((string)$response, true);
46
        //interceptors after current pipeline are ignored
47
        $this->assertSame(['skip', 'three', 'two', 'one', 'one'], $output);
48
    }
49
50
    public function testSkipIfFirst(): void
51
    {
52
        $response = $this->get('/intercepted/first')->getBody();
53
        $output = json_decode((string)$response, true);
54
        //interceptors after current pipeline are ignored
55
        $this->assertSame(['first', 'three', 'two', 'one'], $output);
56
    }
57
58
    public function testWithAttribute(): void
59
    {
60
        $response = $this->get('/intercepted/withAttribute')->getBody();
61
        $output = json_decode((string)$response, true);
62
        $this->assertSame(['withAttribute', 'three', 'two', 'one'], $output);
63
    }
64
65
    public function testMixAttribute(): void
66
    {
67
        $response = $this->get('/intercepted/mixAttribute')->getBody();
68
        $output = json_decode((string)$response, true);
69
        //pipeline interceptors are injected into the middle
70
        $this->assertSame(['mixAttribute', 'six', 'three', 'two', 'one', 'five', 'four'], $output);
71
    }
72
73
    public function testDupAttribute(): void
74
    {
75
        $response = $this->get('/intercepted/dupAttribute')->getBody();
76
        $output = json_decode((string)$response, true);
77
        //pipeline interceptors are added to the end
78
        $this->assertSame(['dupAttribute', 'three', 'two', 'one', 'three', 'two', 'one'], $output);
79
    }
80
81
    public function testSkipNextAttribute(): void
82
    {
83
        $response = $this->get('/intercepted/skipAttribute')->getBody();
84
        $output = json_decode((string)$response, true);
85
        //interceptors after current pipeline are ignored
86
        $this->assertSame(['skipAttribute', 'three', 'two', 'one', 'one'], $output);
87
    }
88
89
    public function testSkipIfFirstAttribute(): void
90
    {
91
        $response = $this->get('/intercepted/firstAttribute')->getBody();
92
        $output = json_decode((string)$response, true);
93
        //interceptors after current pipeline are ignored
94
        $this->assertSame(['firstAttribute', 'three', 'two', 'one'], $output);
95
    }
96
}
97