Passed
Pull Request — master (#370)
by Valentin
04:51
created

PipelineInterceptorTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 19
c 1
b 0
f 1
dl 0
loc 47
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testSkipIfFirst() 0 6 1
A testWith() 0 5 1
A testDup() 0 6 1
A testWithoutPipeline() 0 6 1
A testMix() 0 6 1
A testSkipNext() 0 6 1
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, 512, JSON_THROW_ON_ERROR);
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, 512, JSON_THROW_ON_ERROR);
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, 512, JSON_THROW_ON_ERROR);
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, 512, JSON_THROW_ON_ERROR);
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, 512, JSON_THROW_ON_ERROR);
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, 512, JSON_THROW_ON_ERROR);
54
        //interceptors after current pipeline are ignored
55
        $this->assertSame(['first', 'three', 'two', 'one'], $output);
56
    }
57
}
58