FlowCollectionTest::testCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
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;
15
16
use Graze\DataFlow\Flow\FlowCollection;
17
use Graze\DataFlow\Flow\Runner\Run;
18
use Graze\DataFlow\FlowInterface;
19
use Graze\DataFlow\Test\TestCase;
20
use IteratorAggregate;
21
use Mockery as m;
22
use Serializable;
23
24
class FlowCollectionTest extends TestCase
25
{
26
    public function testInstanceOf()
27
    {
28
        $collection = new FlowCollection();
29
        static::assertInstanceOf(Serializable::class, $collection);
30
        static::assertInstanceOf(IteratorAggregate::class, $collection);
31
    }
32
33 View Code Duplication
    public function testConstructWithMultipleFlows()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
34
    {
35
        $flow1 = m::mock(FlowInterface::class);
36
        $flow2 = m::mock(FlowInterface::class);
37
38
        $collection = new FlowCollection($flow1, $flow2);
39
40
        static::assertEquals([$flow1, $flow2], $collection->getAll());
41
    }
42
43
    public function testAddWillAppendTheFlow()
44
    {
45
        $flow1 = m::mock(FlowInterface::class);
46
        $flow2 = m::mock(FlowInterface::class);
47
48
        $collection = new FlowCollection($flow1, $flow2);
49
50
        $flow3 = m::mock(FlowInterface::class);
51
        $collection->add($flow3);
52
53
        static::assertEquals([$flow1, $flow2, $flow3], $collection->getAll());
54
    }
55
56
    public function testAddFlowsWillAppendTheFlow()
57
    {
58
        $flow1 = m::mock(FlowInterface::class);
59
        $flow2 = m::mock(FlowInterface::class);
60
61
        $collection = new FlowCollection($flow1, $flow2);
62
63
        $flow3 = m::mock(FlowInterface::class);
64
        $flow4 = m::mock(FlowInterface::class);
65
66
        $collection->addFlows([$flow3, $flow4]);
67
68
        static::assertEquals([$flow1, $flow2, $flow3, $flow4], $collection->getAll());
69
    }
70
71
    public function testContains()
72
    {
73
        $flow1 = m::mock(FlowInterface::class);
74
        $flow2 = m::mock(FlowInterface::class);
75
76
        $collection = new FlowCollection($flow1, $flow2);
77
78
        static::assertTrue($collection->contains($flow1));
79
80
        $flow3 = m::mock(FlowInterface::class);
81
82
        static::assertFalse($collection->contains($flow3));
83
    }
84
85
    public function testCount()
86
    {
87
        $flow1 = m::mock(FlowInterface::class);
88
        $flow2 = m::mock(FlowInterface::class);
89
90
        $collection = new FlowCollection($flow1, $flow2);
91
92
        static::assertEquals(2, $collection->count());
93
    }
94
95
    public function testRemove()
96
    {
97
        $flow1 = m::mock(FlowInterface::class);
98
        $flow2 = m::mock(FlowInterface::class);
99
100
        $collection = new FlowCollection($flow1, $flow2);
101
102
        static::assertEquals(2, $collection->count());
103
104
        $collection->remove($flow2);
105
106
        static::assertEquals(1, $collection->count());
107
    }
108
109 View Code Duplication
    public function testIterator()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
110
    {
111
        $flow1 = m::mock(FlowInterface::class);
112
        $flow2 = m::mock(FlowInterface::class);
113
114
        $collection = new FlowCollection($flow1, $flow2);
115
116
        foreach ($collection->getIterator() as $flow) {
117
            static::assertContains($flow, [$flow1, $flow2]);
118
        }
119
    }
120
121
    public function testSerialize()
122
    {
123
        $flow1 = new Run();
124
125
        $collection = new FlowCollection($flow1);
126
127
        $serialized = $collection->serialize();
128
129
        $newCollection = new FlowCollection();
130
        $newCollection->unserialize($serialized);
131
132
        static::assertEquals(1, $newCollection->count());
133
    }
134
}
135