1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use GroupByInc\API\Util\ArrayUtils; |
4
|
|
|
|
5
|
|
|
class ArrayUtilsTest extends PHPUnit_Framework_TestCase |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
/** @var string[] */ |
8
|
|
|
private $array; |
9
|
|
|
|
10
|
|
|
public function setUp() |
11
|
|
|
{ |
12
|
|
|
$this->array = array("a", "bunch", "of", "words", "in", "an", "array");; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
View Code Duplication |
public function testRemoveFromArrayByIndex() |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
ArrayUtils::removeByIndex($this->array, 0); |
18
|
|
|
$this->assertEquals(6, count($this->array)); |
19
|
|
|
$this->assertEquals(array("bunch", "of", "words", "in", "an", "array"), $this->array); |
20
|
|
|
|
21
|
|
|
ArrayUtils::removeByIndex($this->array, 2); |
22
|
|
|
$this->assertEquals(5, count($this->array)); |
23
|
|
|
$this->assertEquals(array("bunch", "of", "in", "an", "array"), $this->array); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testGetElementOnRemoveByIndex() |
27
|
|
|
{ |
28
|
|
|
$this->assertEquals("a", ArrayUtils::removeByIndex($this->array, 0)); |
29
|
|
|
$this->assertEquals("bunch", ArrayUtils::removeByIndex($this->array, 0)); |
30
|
|
|
$this->assertEquals("of", ArrayUtils::removeByIndex($this->array, 0)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
View Code Duplication |
public function testRemoveFromArray() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
ArrayUtils::remove($this->array, "a"); |
36
|
|
|
$this->assertEquals(6, count($this->array)); |
37
|
|
|
$this->assertEquals(array("bunch", "of", "words", "in", "an", "array"), $this->array); |
38
|
|
|
|
39
|
|
|
ArrayUtils::remove($this->array, "words"); |
40
|
|
|
$this->assertEquals(5, count($this->array)); |
41
|
|
|
$this->assertEquals(array("bunch", "of", "in", "an", "array"), $this->array); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
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.