|
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
|
|
|
|