1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/data-flow |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/data-flow/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/data-flow |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\DataFlow\Test\Unit\Runner; |
15
|
|
|
|
16
|
|
|
use Graze\DataFlow\Flow; |
17
|
|
|
use Graze\DataFlow\Flow\FlowCollection; |
18
|
|
|
use Graze\DataFlow\Flow\Runner\ToAll; |
19
|
|
|
use Graze\DataFlow\FlowInterface; |
20
|
|
|
use Graze\DataFlow\Test\TestCase; |
21
|
|
|
use Graze\DataNode\NodeCollection; |
22
|
|
|
use Graze\DataNode\NodeInterface; |
23
|
|
|
use Mockery as m; |
24
|
|
|
|
25
|
|
|
class ToAllTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
public function testInstanceOf() |
28
|
|
|
{ |
29
|
|
|
$runner = new ToAll(); |
30
|
|
|
static::assertInstanceOf(FlowCollection::class, $runner); |
31
|
|
|
static::assertInstanceOf(FlowInterface::class, $runner); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
View Code Duplication |
public function testRunIndependent() |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
$flow1 = m::mock(FlowInterface::class); |
37
|
|
|
$flow2 = m::mock(FlowInterface::class); |
38
|
|
|
|
39
|
|
|
$runner = new ToAll($flow1, $flow2); |
40
|
|
|
|
41
|
|
|
$node1 = m::mock(NodeInterface::class); |
42
|
|
|
$node2 = m::mock(NodeInterface::class); |
43
|
|
|
$node3 = m::mock(NodeInterface::class); |
44
|
|
|
|
45
|
|
|
$flow1->shouldReceive('flow') |
46
|
|
|
->with($node1) |
47
|
|
|
->andReturn($node2); |
48
|
|
|
$flow2->shouldReceive('flow') |
49
|
|
|
->with($node1) |
50
|
|
|
->andReturn($node3); |
51
|
|
|
|
52
|
|
|
$output = $runner->flow($node1); |
53
|
|
|
|
54
|
|
|
static::assertInstanceOf(NodeCollection::class, $output); |
55
|
|
|
|
56
|
|
|
static::assertEquals([$node2, $node3], $output->getAll()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
View Code Duplication |
public function testStaticInstance() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$flow1 = m::mock(FlowInterface::class); |
62
|
|
|
$flow2 = m::mock(FlowInterface::class); |
63
|
|
|
|
64
|
|
|
$runner = Flow::toAll($flow1, $flow2); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$node1 = m::mock(NodeInterface::class); |
67
|
|
|
$node2 = m::mock(NodeInterface::class); |
68
|
|
|
$node3 = m::mock(NodeInterface::class); |
69
|
|
|
|
70
|
|
|
$flow1->shouldReceive('flow') |
71
|
|
|
->with($node1) |
72
|
|
|
->andReturn($node2); |
73
|
|
|
$flow2->shouldReceive('flow') |
74
|
|
|
->with($node1) |
75
|
|
|
->andReturn($node3); |
76
|
|
|
|
77
|
|
|
$output = $runner->flow($node1); |
78
|
|
|
|
79
|
|
|
static::assertInstanceOf(NodeCollection::class, $output); |
80
|
|
|
|
81
|
|
|
static::assertEquals([$node2, $node3], $output->getAll()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
View Code Duplication |
public function testInvokeFlow() |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
$flow1 = m::mock(FlowInterface::class); |
87
|
|
|
$flow2 = m::mock(FlowInterface::class); |
88
|
|
|
|
89
|
|
|
$runner = Flow::toAll($flow1, $flow2); |
|
|
|
|
90
|
|
|
|
91
|
|
|
$node1 = m::mock(NodeInterface::class); |
92
|
|
|
$node2 = m::mock(NodeInterface::class); |
93
|
|
|
$node3 = m::mock(NodeInterface::class); |
94
|
|
|
|
95
|
|
|
$flow1->shouldReceive('flow') |
96
|
|
|
->with($node1) |
97
|
|
|
->andReturn($node2); |
98
|
|
|
$flow2->shouldReceive('flow') |
99
|
|
|
->with($node1) |
100
|
|
|
->andReturn($node3); |
101
|
|
|
|
102
|
|
|
$output = call_user_func($runner, $node1); |
103
|
|
|
|
104
|
|
|
static::assertInstanceOf(NodeCollection::class, $output); |
105
|
|
|
|
106
|
|
|
static::assertEquals([$node2, $node3], $output->getAll()); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.