|
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; |
|
15
|
|
|
|
|
16
|
|
|
use Graze\DataFile\Node\FileNodeInterface; |
|
17
|
|
|
use Graze\DataFlow\Flow; |
|
18
|
|
|
use Graze\DataFlow\FlowBuilderInterface; |
|
19
|
|
|
use Graze\DataFlow\Test\TestCase; |
|
20
|
|
|
use Graze\DataNode\NodeCollection; |
|
21
|
|
|
use Graze\DataNode\NodeInterface; |
|
22
|
|
|
use Mockery as m; |
|
23
|
|
|
use Psr\Log\LoggerAwareInterface; |
|
24
|
|
|
use Psr\Log\LoggerInterface; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @runTestsInSeparateProcesses |
|
28
|
|
|
* @preserveGlobalState disabled |
|
29
|
|
|
*/ |
|
30
|
|
|
class FlowTest extends TestCase |
|
31
|
|
|
{ |
|
32
|
|
|
public function tearDown() |
|
33
|
|
|
{ |
|
34
|
|
|
parent::tearDown(); |
|
35
|
|
|
m::close(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testFluentChain() |
|
39
|
|
|
{ |
|
40
|
|
|
$node1 = m::mock(FileNodeInterface::class); |
|
41
|
|
|
$node2 = m::mock(NodeInterface::class); |
|
42
|
|
|
|
|
43
|
|
|
$collection = new NodeCollection([$node1, $node2]); |
|
44
|
|
|
|
|
45
|
|
|
$result = Flow::create() |
|
46
|
|
|
->filter(function (NodeInterface $node) { |
|
47
|
|
|
return ($node instanceof FileNodeInterface); |
|
48
|
|
|
}) |
|
49
|
|
|
->first() |
|
50
|
|
|
->flow($collection); |
|
51
|
|
|
|
|
52
|
|
|
static::assertSame($result, $node1); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testSetLoggerSetsTheLoggerOnTheBuilder() |
|
56
|
|
|
{ |
|
57
|
|
|
$builder = m::mock(FlowBuilderInterface::class, LoggerAwareInterface::class); |
|
58
|
|
|
$logger = m::mock(LoggerInterface::class); |
|
59
|
|
|
|
|
60
|
|
|
Flow::setBuilder($builder); |
|
61
|
|
|
$builder->shouldReceive('setLogger') |
|
62
|
|
|
->with($logger) |
|
63
|
|
|
->once(); |
|
64
|
|
|
|
|
65
|
|
|
Flow::useLogger($logger); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testWithWillCallAddNamespaceOnBuilder() |
|
69
|
|
|
{ |
|
70
|
|
|
$builder = m::mock(FlowBuilderInterface::class); |
|
71
|
|
|
Flow::setBuilder($builder); |
|
72
|
|
|
|
|
73
|
|
|
$builder->shouldReceive('addNamespace') |
|
74
|
|
|
->with('Graze\\DataFlow\\') |
|
75
|
|
|
->once(); |
|
76
|
|
|
|
|
77
|
|
|
Flow::with('Graze\\DataFlow\\'); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|