MapTest::testStaticFlow()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
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\Flow\Collection;
15
16
use Graze\DataFlow\Flow;
17
use Graze\DataFlow\Flow\Collection\Map;
18
use Graze\DataFlow\FlowInterface;
19
use Graze\DataFlow\Test\TestCase;
20
use Graze\DataNode\NodeCollectionInterface;
21
use Graze\DataNode\NodeInterface;
22
use InvalidArgumentException;
23
use Mockery as m;
24
25
class MapTest extends TestCase
26
{
27
    public function testInstanceOf()
28
    {
29
        $flow = new Map(function () {
30
            return true;
31
        });
32
33
        static::assertInstanceOf(FlowInterface::class, $flow);
34
    }
35
36
    public function testInvalidInputThrowsAnException()
37
    {
38
        $file = m::mock(NodeInterface::class);
39
        $flow = new Map(function () {
40
        });
41
42
        $this->expectException(InvalidArgumentException::class);
43
44
        $flow->flow($file);
45
    }
46
47
    public function testFlow()
48
    {
49
        $func = function () use (&$called) {
50
            $called = true;
51
            return true;
52
        };
53
        $flow = new Map($func);
54
55
        $node = m::mock(NodeCollectionInterface::class);
56
        $node->shouldReceive('map')
57
             ->with($func)
58
             ->andReturn([]);
59
60
        $response = $flow->flow($node);
61
62
        static::assertNotSame($response, $node);
63
        static::assertInstanceOf(NodeCollectionInterface::class, $response);
64
    }
65
66
    public function testStaticFlow()
67
    {
68
        $func = function () use (&$called) {
69
            $called = true;
70
            return true;
71
        };
72
        $flow = Flow::map($func);
73
74
        $node = m::mock(NodeCollectionInterface::class);
75
        $node->shouldReceive('map')
76
             ->with($func)
77
             ->andReturn([]);
78
79
        $response = $flow->flow($node);
80
81
        static::assertNotSame($response, $node);
82
        static::assertInstanceOf(NodeCollectionInterface::class, $response);
83
    }
84
85
    public function testInvokeFlow()
86
    {
87
        $func = function () use (&$called) {
88
            $called = true;
89
            return true;
90
        };
91
        $flow = Flow::map($func);
92
93
        $node = m::mock(NodeCollectionInterface::class);
94
        $node->shouldReceive('map')
95
             ->with($func)
96
             ->andReturn([]);
97
98
        $response = call_user_func($flow, $node);
99
100
        static::assertNotSame($response, $node);
101
        static::assertInstanceOf(NodeCollectionInterface::class, $response);
102
    }
103
}
104