anonymous//tests/unit/PipeLineTest.php$0   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlow;
5
6
use PHPUnit\Framework\TestCase;
7
use SlayerBirden\DataFlow\Data\SimpleBag;
8
9
class PipeLineTest extends TestCase
10
{
11
    /**
12
     * @var PipeLine
13
     */
14
    private $pipeline;
15
16
    protected function setUp()
17
    {
18
        $this->pipeline = new PipeLine();
19
    }
20
21
    public function testCount()
22
    {
23
        $this->pipeline->insert(new class implements PipeInterface
24
        {
25
            public function pass(DataBagInterface $dataBag): DataBagInterface
26
            {
27
                return new SimpleBag();
28
            }
29
30
            public function getIdentifier(): string
31
            {
32
                return 'handler0';
33
            }
34
        }, 0);
35
36
        $this->pipeline->insert(new class implements PipeInterface
37
        {
38
            public function pass(DataBagInterface $dataBag): DataBagInterface
39
            {
40
                return new SimpleBag();
41
            }
42
43
            public function getIdentifier(): string
44
            {
45
                return 'handler100';
46
            }
47
        }, 100);
48
49
        $this->assertCount(2, $this->pipeline);
50
    }
51
52
    public function testOrder()
53
    {
54
        $this->pipeline->insert(new class implements PipeInterface
55
        {
56
            public function pass(DataBagInterface $dataBag): DataBagInterface
57
            {
58
                return new SimpleBag();
59
            }
60
61
            public function getIdentifier(): string
62
            {
63
                return 'handler0';
64
            }
65
        }, 0);
66
67
        $this->pipeline->insert(new class implements PipeInterface
68
        {
69
            public function pass(DataBagInterface $dataBag): DataBagInterface
70
            {
71
                return new SimpleBag();
72
            }
73
74
            public function getIdentifier(): string
75
            {
76
                return 'handler100';
77
            }
78
        }, 100);
79
80
        $handler = $this->pipeline->current();
81
        $this->assertSame('handler100', $handler->getIdentifier());
82
    }
83
84
    public function testRewind()
85
    {
86
        $this->pipeline->insert(new class implements PipeInterface
87
        {
88
            public function pass(DataBagInterface $dataBag): DataBagInterface
89
            {
90
                return new SimpleBag();
91
            }
92
93
            public function getIdentifier(): string
94
            {
95
                return 'handler0';
96
            }
97
        }, 0);
98
99
        $this->pipeline->insert(new class implements PipeInterface
100
        {
101
            public function pass(DataBagInterface $dataBag): DataBagInterface
102
            {
103
                return new SimpleBag();
104
            }
105
106
            public function getIdentifier(): string
107
            {
108
                return 'handler100';
109
            }
110
        }, 100);
111
112
        $this->pipeline->next();
113
114
        $handler = $this->pipeline->current();
115
        $this->assertSame('handler0', $handler->getIdentifier());
116
117
        $this->pipeline->rewind();
118
        $handler = $this->pipeline->current();
119
        $this->assertSame('handler100', $handler->getIdentifier());
120
    }
121
}
122