forked from zircote/swagger-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PipelineTest.php
115 lines (87 loc) · 2.86 KB
/
PipelineTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php declare(strict_types=1);
/**
* @license Apache 2.0
*/
namespace OpenApi\Tests;
use OpenApi\Pipeline;
class PipelineTest extends OpenApiTestCase
{
public function __invoke($payload)
{
return $payload . 'x';
}
protected function pipe(string $add)
{
return new class($add) {
protected $add;
public function __construct(string $add)
{
$this->add = $add;
}
// ------------------------------------------------------------------------
public function __invoke($payload)
{
return $payload . $this->add;
}
};
}
public function testProcess()
{
$pipeline = new Pipeline([$this->pipe('x')]);
$result = $pipeline->process('');
$this->assertEquals('x', $result);
}
public function testAdd()
{
$pipeline = new Pipeline();
$pipeline->add($this->pipe('a'));
$this->assertEquals('a', $pipeline->process(''));
$pipeline->add($this->pipe('b'));
$this->assertEquals('ab', $pipeline->process(''));
}
public function testRemoveStrict()
{
$pipeline = new Pipeline();
$pipeline->add($pipec = $this->pipe('c'));
$pipeline->add($this->pipe('d'));
$this->assertEquals('cd', $pipeline->process(''));
$pipeline->remove($pipec);
$this->assertEquals('d', $pipeline->process(''));
}
public function testRemoveMatcher()
{
$pipeline = new Pipeline();
$pipeline->add($pipec = $this->pipe('c'));
$pipeline->add($this->pipe('d'));
$this->assertEquals('cd', $pipeline->process(''));
$pipeline->remove(null, function ($pipe) use ($pipec) { return $pipe !== $pipec; });
$this->assertEquals('d', $pipeline->process(''));
}
public function testRemoveClassString()
{
$pipeline = new Pipeline();
$pipeline->add($this->pipe('c'));
$pipeline->add($this);
$this->assertEquals('cx', $pipeline->process(''));
$pipeline->remove(__CLASS__);
$this->assertEquals('c', $pipeline->process(''));
}
public function testInsertMatcher()
{
$pipeline = new Pipeline();
$pipeline->add($this->pipe('x'));
$pipeline->add($this->pipe('z'));
$this->assertEquals('xz', $pipeline->process(''));
$pipeline->insert($this->pipe('y'), function ($pipes) { return 1; });
$this->assertEquals('xyz', $pipeline->process(''));
}
public function testInsertClassString()
{
$pipeline = new Pipeline();
$pipeline->add($this);
$pipeline->add($this->pipe('y'));
$this->assertEquals('xy', $pipeline->process(''));
$pipeline->insert($this->pipe('a'), __CLASS__);
$this->assertEquals('axy', $pipeline->process(''));
}
}