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\Integration; |
15
|
|
|
|
16
|
|
|
use Graze\DataFlow\Builder; |
17
|
|
|
use Graze\DataFlow\Flow; |
18
|
|
|
use Graze\DataFlow\FlowInterface; |
19
|
|
|
use Graze\DataFlow\Test\TestCase; |
20
|
|
|
use Graze\DataNode\NodeCollection; |
21
|
|
|
use Graze\DataNode\NodeInterface; |
22
|
|
|
use InvalidArgumentException; |
23
|
|
|
use Mockery as m; |
24
|
|
|
use Psr\Log\LoggerInterface; |
25
|
|
|
|
26
|
|
|
class BuilderTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var Builder |
30
|
|
|
*/ |
31
|
|
|
private $builder; |
32
|
|
|
|
33
|
|
|
public function setUp() |
34
|
|
|
{ |
35
|
|
|
$this->builder = new Builder(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testCanBuildAKnownFlow() |
39
|
|
|
{ |
40
|
|
|
$flow = $this->builder->buildFlow('gzip'); |
41
|
|
|
static::assertInstanceOf(FlowInterface::class, $flow); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testBuildingUnknownFlowWillThrowException() |
45
|
|
|
{ |
46
|
|
|
$this->expectException(InvalidArgumentException::class); |
47
|
|
|
|
48
|
|
|
$this->builder->buildFlow('someUnknownFlowName'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testBuildingValidClassNameButNotAFlowWillThrowAnException() |
52
|
|
|
{ |
53
|
|
|
$this->expectException(InvalidArgumentException::class); |
54
|
|
|
|
55
|
|
|
$this->builder->buildFlow('flowCollection'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testAddingANamespaceWillSearchThatNamespaceForFlows() |
59
|
|
|
{ |
60
|
|
|
$this->builder->addNamespace('Graze\\DataFlow\\'); |
61
|
|
|
|
62
|
|
|
$flow = $this->builder->buildFlow('flow'); |
63
|
|
|
|
64
|
|
|
static::assertInstanceOf(Flow::class, $flow); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testBuildingAFlowWhenALoggerIsSetWillSetTheLoggerOnTheChild() |
68
|
|
|
{ |
69
|
|
|
$logger = m::mock(LoggerInterface::class); |
70
|
|
|
$this->builder->setLogger($logger); |
71
|
|
|
|
72
|
|
|
$logger->shouldReceive('log') |
73
|
|
|
->times(2); |
74
|
|
|
|
75
|
|
|
$flow = $this->builder->buildFlow('first'); |
76
|
|
|
|
77
|
|
|
$collection = new NodeCollection(); |
78
|
|
|
$node = m::mock(NodeInterface::class); |
79
|
|
|
$collection->add($node); |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
$first = $flow->flow($collection); |
83
|
|
|
|
84
|
|
|
static::assertEquals($node, $first); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testBuildingAnInstanceWillReturnTheInstance() |
88
|
|
|
{ |
89
|
|
|
$flow = m::mock(FlowInterface::class); |
90
|
|
|
$return = $this->builder->buildFlow($flow); |
91
|
|
|
|
92
|
|
|
static::assertSame($flow, $return); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testBuildingACompleteClassNameWillBuildTheclass() |
96
|
|
|
{ |
97
|
|
|
$flow = $this->builder->buildFlow(Flow::class); |
98
|
|
|
static::assertInstanceOf(Flow::class, $flow); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|