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 | /** |
||
4 | * This file is part of the Cubiche package. |
||
5 | * |
||
6 | * Copyright (c) Cubiche |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | namespace Cubiche\Core\Collections\Tests\Units\ArrayCollection; |
||
12 | |||
13 | use Cubiche\Core\Collections\ArrayCollection\ArraySet; |
||
14 | use Cubiche\Core\Collections\ArrayCollection\ArraySetInterface; |
||
15 | use Cubiche\Core\Collections\Exception\InvalidKeyException; |
||
16 | use Cubiche\Core\Collections\Tests\Units\SetTestCase; |
||
17 | use Cubiche\Core\Equatable\Tests\Fixtures\Value; |
||
18 | |||
19 | /** |
||
20 | * ArraySetTests class. |
||
21 | * |
||
22 | * @method protected ArraySetInterface randomCollection($size = null) |
||
23 | * |
||
24 | * @author Ivannis Suárez Jerez <[email protected]> |
||
25 | */ |
||
26 | class ArraySetTests extends SetTestCase |
||
27 | { |
||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | protected function emptyCollection() |
||
32 | { |
||
33 | return new ArraySet(); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | protected function randomValue() |
||
40 | { |
||
41 | return new Value(\rand(0, 100)); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | protected function uniqueValue() |
||
48 | { |
||
49 | return new Value(1000); |
||
50 | } |
||
51 | |||
52 | /* |
||
53 | * Test create. |
||
54 | */ |
||
55 | public function testCreate() |
||
56 | { |
||
57 | $this |
||
58 | ->given($collection = $this->randomCollection()) |
||
59 | ->then() |
||
60 | ->set($collection) |
||
61 | ->isInstanceOf(ArraySetInterface::class) |
||
62 | ; |
||
63 | } |
||
64 | |||
65 | /* |
||
66 | * Test contains. |
||
67 | */ |
||
68 | View Code Duplication | public function testContains() |
|
0 ignored issues
–
show
|
|||
69 | { |
||
70 | $this |
||
71 | ->given( |
||
72 | $unique = $this->uniqueValue(), |
||
73 | $collection = $this->randomCollection() |
||
74 | ) |
||
75 | ->then() |
||
76 | ->boolean($collection->contains($unique)) |
||
77 | ->isFalse() |
||
78 | ->and |
||
79 | ->when($collection->add($unique)) |
||
80 | ->then() |
||
81 | ->boolean($collection->contains($unique)) |
||
82 | ->isTrue() |
||
83 | ; |
||
84 | } |
||
85 | |||
86 | /* |
||
87 | * Test containsAll. |
||
88 | */ |
||
89 | public function testContainsAll() |
||
90 | { |
||
91 | $this |
||
92 | ->given( |
||
93 | $unique = $this->uniqueValue(), |
||
94 | $other = 'foo', |
||
95 | $collection = $this->randomCollection() |
||
96 | ) |
||
97 | ->then() |
||
98 | ->boolean($collection->contains($unique)) |
||
99 | ->isFalse() |
||
100 | ->boolean($collection->contains($other)) |
||
101 | ->isFalse() |
||
102 | ->and |
||
103 | ->when($collection->addAll([$unique, $other])) |
||
104 | ->then() |
||
105 | ->boolean($collection->containsAll([$unique, $other])) |
||
106 | ->isTrue() |
||
107 | ->boolean($collection->containsAll([$unique, 'hjgasd756'])) |
||
108 | ->isFalse() |
||
109 | ; |
||
110 | } |
||
111 | |||
112 | /* |
||
113 | * Test sort. |
||
114 | */ |
||
115 | 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. ![]() |
|||
116 | { |
||
117 | $this |
||
118 | ->given( |
||
119 | $comparator = $this->comparator(), |
||
120 | $reverseComparator = $comparator->reverse(), |
||
121 | $collection = $this->randomCollection() |
||
122 | ) |
||
123 | ->when($collection->sort()) |
||
124 | ->then() |
||
125 | ->set($collection) |
||
126 | ->isSortedUsing($comparator) |
||
127 | ->and |
||
128 | ->when($collection->sort($reverseComparator)) |
||
129 | ->then() |
||
130 | ->set($collection) |
||
131 | ->isSortedUsing($reverseComparator) |
||
132 | ->set($collection) |
||
133 | ->isNotSortedUsing($comparator) |
||
134 | ; |
||
135 | } |
||
136 | |||
137 | /* |
||
138 | * Test offsetExists. |
||
139 | */ |
||
140 | public function testOffsetExists() |
||
141 | { |
||
142 | $this |
||
143 | ->given( |
||
144 | $key = 0, |
||
145 | $unique = $this->uniqueValue(), |
||
146 | $collection = $this->emptyCollection() |
||
147 | ) |
||
148 | ->then() |
||
149 | ->boolean(isset($collection[$key])) |
||
150 | ->isFalse() |
||
151 | ->and |
||
152 | ->when($collection->add($unique)) |
||
153 | ->then() |
||
154 | ->boolean(isset($collection[$key])) |
||
155 | ->isTrue() |
||
156 | ->exception(function () use ($collection) { |
||
157 | isset($collection['foo']); |
||
158 | })->isInstanceOf(InvalidKeyException::class) |
||
159 | ; |
||
160 | } |
||
161 | |||
162 | /* |
||
163 | * Test offsetGet. |
||
164 | */ |
||
165 | View Code Duplication | public function testOffsetGet() |
|
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. ![]() |
|||
166 | { |
||
167 | $this |
||
168 | ->given( |
||
169 | $key = 0, |
||
170 | $unique = $this->uniqueValue(), |
||
171 | $collection = $this->emptyCollection() |
||
172 | ) |
||
173 | ->then() |
||
174 | ->variable($collection[$key]) |
||
175 | ->isNull() |
||
176 | ->and |
||
177 | ->when($collection->add($unique)) |
||
178 | ->then() |
||
179 | ->variable($collection[$key]) |
||
180 | ->isEqualTo($unique) |
||
181 | ; |
||
182 | } |
||
183 | |||
184 | /* |
||
185 | * Test offsetSet. |
||
186 | */ |
||
187 | View Code Duplication | public function testOffsetSet() |
|
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. ![]() |
|||
188 | { |
||
189 | $this |
||
190 | ->given( |
||
191 | $key = 5, |
||
192 | $unique = $this->uniqueValue(), |
||
193 | $collection = $this->emptyCollection() |
||
194 | ) |
||
195 | ->when($collection[$key] = $unique) |
||
196 | ->then() |
||
197 | ->variable($collection[$key]) |
||
198 | ->isNull() |
||
199 | ->variable($collection[0]) |
||
200 | ->isEqualTo($unique) |
||
201 | ; |
||
202 | } |
||
203 | |||
204 | /* |
||
205 | * Test offsetUnset. |
||
206 | */ |
||
207 | View Code Duplication | public function testOffsetUnset() |
|
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. ![]() |
|||
208 | { |
||
209 | $this |
||
210 | ->given( |
||
211 | $key = 0, |
||
212 | $unique = $this->uniqueValue(), |
||
213 | $collection = $this->emptyCollection() |
||
214 | ) |
||
215 | ->when($collection[$key] = $unique) |
||
216 | ->then() |
||
217 | ->variable($collection[$key]) |
||
218 | ->isEqualTo($unique) |
||
219 | ->and() |
||
220 | ->when(function () use ($collection, $key) { |
||
221 | unset($collection[$key]); |
||
222 | }) |
||
223 | ->then() |
||
224 | ->variable($collection[$key]) |
||
225 | ->isNull() |
||
226 | ; |
||
227 | } |
||
228 | } |
||
229 |
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.