This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Graze\DataStructure\Collection; |
||
4 | |||
5 | use Graze\Sort as s; |
||
6 | use PHPUnit_Framework_TestCase as TestCase; |
||
7 | |||
8 | class CollectionTest extends TestCase |
||
9 | { |
||
10 | public function testInterface() |
||
11 | { |
||
12 | $coll = new Collection(); |
||
13 | |||
14 | $this->assertInstanceOf('Graze\DataStructure\Collection\CollectionInterface', $coll); |
||
15 | $this->assertInstanceOf('Serializable', $coll); |
||
16 | } |
||
17 | |||
18 | public function testConstructor() |
||
19 | { |
||
20 | $items = ['foo', 'bar', 'baz']; |
||
21 | $coll = new Collection($items); |
||
22 | |||
23 | $this->assertEquals($items, $coll->getAll()); |
||
24 | } |
||
25 | |||
26 | public function testAdd() |
||
27 | { |
||
28 | $coll = new Collection(['foo', 'bar']); |
||
29 | $result = $coll->add('baz'); |
||
30 | |||
31 | $this->assertEquals(['foo', 'bar', 'baz'], $coll->getAll()); |
||
32 | $this->assertSame($coll, $result); |
||
33 | } |
||
34 | |||
35 | public function testAddDuplicate() |
||
36 | { |
||
37 | $coll = new Collection(['foo', 'bar', 'baz']); |
||
38 | $result = $coll->add('baz'); |
||
39 | |||
40 | $this->assertEquals(['foo', 'bar', 'baz', 'baz'], $coll->getAll()); |
||
41 | $this->assertSame($coll, $result); |
||
42 | } |
||
43 | |||
44 | public function testContainsIsTrue() |
||
45 | { |
||
46 | $coll = new Collection(['foo', 'bar', 'baz']); |
||
47 | |||
48 | $this->assertTrue($coll->contains('foo')); |
||
49 | } |
||
50 | |||
51 | public function testContainsIsFalse() |
||
52 | { |
||
53 | $coll = new Collection(['FOO', 'bar', 'baz']); |
||
54 | |||
55 | $this->assertFalse($coll->contains('foo')); |
||
56 | } |
||
57 | |||
58 | public function testContainsIsStrict() |
||
59 | { |
||
60 | $coll = new Collection([0, 1]); |
||
61 | |||
62 | $this->assertFalse($coll->contains(false)); |
||
63 | } |
||
64 | |||
65 | public function testCount() |
||
66 | { |
||
67 | $coll = new Collection(['foo', 'bar', 'baz']); |
||
68 | |||
69 | $this->assertEquals(3, count($coll)); |
||
70 | } |
||
71 | |||
72 | View Code Duplication | public function testFilter() |
|
0 ignored issues
–
show
|
|||
73 | { |
||
74 | $coll = new Collection(['foo', 'bar', 'baz']); |
||
75 | $result = $coll->filter(function ($item) { |
||
76 | return 'foo' !== $item; |
||
77 | }); |
||
78 | |||
79 | $this->assertEquals(['bar', 'baz'], $coll->getAll()); |
||
80 | $this->assertSame($coll, $result); |
||
81 | } |
||
82 | |||
83 | public function testGetIterator() |
||
84 | { |
||
85 | $coll = new Collection(); |
||
86 | |||
87 | $this->assertInstanceOf('Iterator', $coll->getIterator()); |
||
88 | } |
||
89 | |||
90 | View Code Duplication | public function testMap() |
|
0 ignored issues
–
show
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. ![]() |
|||
91 | { |
||
92 | $coll = new Collection(['foo', 'bar', 'baz']); |
||
93 | $result = $coll->map(function ($item) { |
||
94 | return $item[0]; |
||
95 | }); |
||
96 | |||
97 | $this->assertEquals(['f', 'b', 'b'], $result); |
||
98 | } |
||
99 | |||
100 | View Code Duplication | public function testReduce() |
|
0 ignored issues
–
show
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. ![]() |
|||
101 | { |
||
102 | $coll = new Collection(['foo', 'bar', 'baz']); |
||
103 | $result = $coll->reduce(function ($carry, $item) { |
||
104 | return $carry . $item; |
||
105 | }); |
||
106 | |||
107 | $this->assertEquals('foobarbaz', $result); |
||
108 | } |
||
109 | |||
110 | View Code Duplication | public function testSort() |
|
0 ignored issues
–
show
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. ![]() |
|||
111 | { |
||
112 | $coll = new Collection([2, 3, 1]); |
||
113 | $result = $coll->sort(s\comparison_fn(function ($item) { |
||
114 | return $item; |
||
115 | })); |
||
116 | |||
117 | $this->assertEquals([1, 2, 3], $coll->getAll()); |
||
118 | $this->assertSame($coll, $result); |
||
119 | } |
||
120 | |||
121 | View Code Duplication | public function testSortOnAsc() |
|
0 ignored issues
–
show
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. ![]() |
|||
122 | { |
||
123 | $coll = new Collection([2, 3, 1]); |
||
124 | $result = $coll->sortOn(function ($item) { |
||
125 | return $item; |
||
126 | }); |
||
127 | |||
128 | $this->assertEquals([1, 2, 3], $coll->getAll()); |
||
129 | $this->assertSame($coll, $result); |
||
130 | } |
||
131 | |||
132 | View Code Duplication | public function testSortOnDesc() |
|
0 ignored issues
–
show
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. ![]() |
|||
133 | { |
||
134 | $coll = new Collection([2, 3, 1]); |
||
135 | $result = $coll->sortOn(function ($item) { |
||
136 | return $item; |
||
137 | }, s\DESC); |
||
138 | |||
139 | $this->assertEquals([3, 2, 1], $coll->getAll()); |
||
140 | $this->assertSame($coll, $result); |
||
141 | } |
||
142 | |||
143 | public function testSerialize() |
||
144 | { |
||
145 | $cont = new Collection(['foo', 'bar', 'baz']); |
||
146 | |||
147 | $this->assertEquals('C:41:"Graze\DataStructure\Collection\Collection":48:{a:3:{i:0;s:3:"foo";i:1;s:3:"bar";i:2;s:3:"baz";}}', serialize($cont)); |
||
148 | } |
||
149 | |||
150 | public function testUnserialize() |
||
151 | { |
||
152 | $cont = unserialize('C:41:"Graze\DataStructure\Collection\Collection":48:{a:3:{i:0;s:3:"foo";i:1;s:3:"bar";i:2;s:3:"baz";}}'); |
||
153 | |||
154 | $this->assertEquals(['foo', 'bar', 'baz'], $cont->getAll()); |
||
155 | } |
||
156 | } |
||
157 |
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.