|
1
|
|
|
<?php |
|
2
|
|
|
class CollectionTest extends PHPUnit_Framework_TestCase { |
|
|
|
|
|
|
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
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testCount() |
|
23
|
|
|
{ |
|
24
|
|
|
$arr = array(1, 2, 3); |
|
25
|
|
|
$collection = new \Suricate\Collection($arr); |
|
26
|
|
|
$this->assertEquals(3, $collection->count()); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testFirst() |
|
30
|
|
|
{ |
|
31
|
|
|
$arr = array(4, 5, 6); |
|
32
|
|
|
$collection = new \Suricate\Collection($arr); |
|
33
|
|
|
$this->assertEquals(4, $collection->first()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testLast() |
|
37
|
|
|
{ |
|
38
|
|
|
$arr = array(1, 2, 3); |
|
39
|
|
|
$collection = new \Suricate\Collection($arr); |
|
40
|
|
|
$this->assertEquals(3, $collection->last()); |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
$collection = new \Suricate\Collection(); |
|
44
|
|
|
$this->assertEquals(null, $collection->last()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testSum() |
|
48
|
|
|
{ |
|
49
|
|
|
$arr = array(1, 2, 3); |
|
50
|
|
|
$collection = new \Suricate\Collection($arr); |
|
51
|
|
|
$this->assertEquals(6, $collection->sum()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testHas() |
|
55
|
|
|
{ |
|
56
|
|
|
$arr = array('a' => 1, 'b' => 2, 'c' => 3); |
|
57
|
|
|
$collection = new \Suricate\Collection($arr); |
|
58
|
|
|
$this->assertEquals(true, $collection->has('b')); |
|
59
|
|
|
$this->assertEquals(false, $collection->has('d')); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testFilter() |
|
63
|
|
|
{ |
|
64
|
|
|
$arr = array('a' => 1, 'b' => 2, 'c' => 3); |
|
65
|
|
|
$collection = new \Suricate\Collection($arr); |
|
66
|
|
|
$this->assertEquals(['b' => 2], $collection->filter( |
|
67
|
|
|
function ($value, $key) { |
|
68
|
|
|
return ($value % 2) === 0; |
|
69
|
|
|
}) |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testPush() |
|
74
|
|
|
{ |
|
75
|
|
|
$arr = array(1, 2, 3); |
|
76
|
|
|
$collection = new \Suricate\Collection($arr); |
|
77
|
|
|
$this->assertEquals([1, 2, 3, 4], $collection->push(4)); |
|
78
|
|
|
} |
|
79
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.