Skip to content

Commit 1dc58b8

Browse files
authored
Merge pull request #25 from rdohms/bug/build-issue
Include ArrayAccessible class
2 parents aef3416 + 310b3f2 commit 1dc58b8

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

composer.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
"autoload-dev": {
2626
"psr-4": {
2727
"DMS\\PHPUnitExtensions\\ArraySubset\\Tests\\": "tests"
28-
},
29-
"classmap": [
30-
"vendor/phpunit/phpunit/tests/"
31-
]
28+
}
3229
}
3330
}

src/ArrayAccessible.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace DMS\PHPUnitExtensions\ArraySubset;
4+
5+
use ArrayAccess;
6+
use ArrayIterator;
7+
use IteratorAggregate;
8+
9+
class ArrayAccessible implements ArrayAccess, IteratorAggregate
10+
{
11+
private $array;
12+
13+
public function __construct(array $array = [])
14+
{
15+
$this->array = $array;
16+
}
17+
18+
public function offsetExists($offset)
19+
{
20+
return \array_key_exists($offset, $this->array);
21+
}
22+
23+
public function offsetGet($offset)
24+
{
25+
return $this->array[$offset];
26+
}
27+
28+
public function offsetSet($offset, $value): void
29+
{
30+
if (null === $offset) {
31+
$this->array[] = $value;
32+
} else {
33+
$this->array[$offset] = $value;
34+
}
35+
}
36+
37+
public function offsetUnset($offset): void
38+
{
39+
unset($this->array[$offset]);
40+
}
41+
42+
public function getIterator()
43+
{
44+
return new ArrayIterator($this->array);
45+
}
46+
}

tests/Unit/Constraint/ArraySubsetTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace DMS\PHPUnitExtensions\ArraySubset\Tests\Unit\Constraint;
55

6-
use ArrayAccessible;
6+
use DMS\PHPUnitExtensions\ArraySubset\ArrayAccessible;
77
use ArrayObject;
88
use Countable;
99
use DMS\PHPUnitExtensions\ArraySubset\Constraint\ArraySubset;

0 commit comments

Comments
 (0)