Completed
Push — master ( 517c7e...70152b )
by Mathieu
01:42
created

CollectionTest::testPrepend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
class CollectionTest extends PHPUnit_Framework_TestCase {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
3
    public function testConstruct()
4
    {
5
        $arr = array(1,2,3);
6
        $collection = new \Suricate\Collection($arr);
7
        $this->assertEquals($arr, $collection->getItems());
8
    }
9
10
    public function testIsEmpty()
11
    {
12
        $arr = array();
13
        $collection = new \Suricate\Collection($arr);
14
        $this->assertEquals(true, $collection->isEmpty());
15
    }
16
17
    public function testUnique()
18
    {
19
       $arr = array(1, 2, 1,3);
20
       $collection = new \Suricate\Collection($arr);
21
        $this->assertEquals([0 => 1, 1 => 2,3 => 3], $collection->unique()->getItems()); 
22
    }
23
24
    public function testCount()
25
    {
26
        $arr = array(1, 2, 3);
27
        $collection = new \Suricate\Collection($arr);
28
        $this->assertEquals(3, $collection->count());
29
    }
30
31
    public function testFirst()
32
    {
33
        $arr = array(4, 5, 6);
34
        $collection = new \Suricate\Collection($arr);
35
        $this->assertEquals(4, $collection->first());
36
    }
37
38
    public function testLast()
39
    {
40
        $arr = array(1, 2, 3);
41
        $collection = new \Suricate\Collection($arr);
42
        $this->assertEquals(3, $collection->last());
43
44
45
        $collection = new \Suricate\Collection();
46
        $this->assertEquals(null, $collection->last());
47
    }
48
49
    public function testSum()
50
    {
51
        $arr = array(1, 2, 3);
52
        $collection = new \Suricate\Collection($arr);
53
        $this->assertEquals(6, $collection->sum());
54
    }
55
56
    public function testHas()
57
    {
58
        $arr = array('a' => 1, 'b' => 2, 'c' => 3);
59
        $collection = new \Suricate\Collection($arr);
60
        $this->assertEquals(true, $collection->has('b'));
61
        $this->assertEquals(false, $collection->has('d'));
62
    }
63
64
	public function testKeys()
65
	{
66
		$arr = array('a' => 1, 'b' => 2, 'c' => 3);
67
        $collection = new \Suricate\Collection($arr);
68
		$this->assertEquals(['a', 'b', 'c'], $collection->keys());
69
	}
70
71
	public function testPrepend()
72
	{
73
		$arr = [4, 5, 6];
74
        $collection = new \Suricate\Collection($arr);
75
		$collection->prepend(99);
76
		$this->assertEquals([99, 4, 5, 6], $collection->getItems());
77
	}
78
	
79
	public function testPut()
80
	{
81
		$arr = array('a' => 1, 'b' => 2, 'c' => 3);
82
        $collection = new \Suricate\Collection($arr);
83
		$collection->put('z', 99);
84
		$this->assertEquals(['a' => 1, 'b' => 2, 'c' => 3, 'z' => 99], $collection->getItems());
85
	}
86
87 View Code Duplication
	public function testShift()
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...
88
	{
89
		$arr = array('a' => 1, 'b' => 2, 'c' => 3);
90
        $collection = new \Suricate\Collection($arr);
91
		$t = $collection->shift();
92
		$this->assertEquals(1, $t);
93
		$this->assertEquals(['b' => 2, 'c' => 3], $collection->getItems());
94
	}
95
96 View Code Duplication
	public function testPop()
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...
97
	{
98
		$arr = array('a' => 1, 'b' => 2, 'c' => 3);
99
        $collection = new \Suricate\Collection($arr);
100
		$t = $collection->pop();
101
		$this->assertEquals(3, $t);
102
		$this->assertEquals(['a' => 1, 'b' => 2], $collection->getItems());
103
	}
104
105 View Code Duplication
	public function testReverse()
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...
106
	{
107
		$arr = array('a' => 1, 'b' => 2, 'c' => 3);
108
        $collection = new \Suricate\Collection($arr);
109
		$t = $collection->reverse();
110
		$this->assertEquals(['c' => 3, 'b' => 2, 'a' => 1], $t->getItems());
111
	}
112
113
	public function testReduce()
114
	{
115
116
	}
117
118
	public function testSlice()
119
	{
120
121
	}
122
	
123 View Code Duplication
	public function testTake()
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...
124
	{
125
		$arr = array('a' => 1, 'b' => 2, 'c' => 3);
126
        $collection = new \Suricate\Collection($arr);
127
		$t = $collection->take(2);
128
		$this->assertEquals(['a' => 1, 'b' => 2], $t->getItems());
129
		
130
	}
131
132
133
    public function testFilter()
134
    {
135
        $arr = array('a' => 1, 'b' => 2, 'c' => 3);
136
        $collection = new \Suricate\Collection($arr);
137
        $this->assertEquals(['b' => 2],  $collection->filter(
138
            function($value) {
139
                return ($value % 2) === 0;
140
            })->getItems()
141
        );
142
    }
143
144
    public function testPush()
145
    {
146
        $arr = array(1, 2, 3);
147
        $collection = new \Suricate\Collection($arr);
148
        $this->assertEquals([1, 2, 3, 4], $collection->push(4)->getItems());
149
    }
150
}
151