Skip to content

Commit 21cffca

Browse files
committed
Do not rely on fixture from phpunit tests directory
1 parent 5503d65 commit 21cffca

File tree

3 files changed

+64
-19
lines changed

3 files changed

+64
-19
lines changed

composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@
113113
"autoload-dev": {
114114
"psr-4": {
115115
"ApiPlatform\\Core\\Tests\\": "tests/"
116-
},
117-
"classmap": [
118-
"vendor/phpunit/phpunit/tests/"
119-
]
116+
}
120117
},
121118
"extra": {
122119
"branch-alias": {

tests/Bridge/Symfony/Bundle/Test/Constraint/ArraySubsetTest.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@
1414
namespace ApiPlatform\Core\Tests\Bridge\Symfony\Bundle\Test\Constraint;
1515

1616
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Constraint\ArraySubset;
17-
use ArrayAccessible;
18-
use ArrayObject;
19-
use Countable;
17+
use ApiPlatform\Core\Tests\Fixtures\ArrayAccessible;
2018
use PHPUnit\Framework\ExpectationFailedException;
2119
use PHPUnit\Framework\SelfDescribing;
2220
use PHPUnit\Framework\TestCase;
2321
use PHPUnit\Runner\Version;
24-
use ReflectionClass;
2522
use SebastianBergmann\RecursionContext\InvalidArgumentException;
26-
use Traversable;
27-
use function sprintf;
2823

2924
/**
3025
* Imported from dms/phpunit-arraysubset-asserts, because the original constraint has been deprecated.
@@ -64,22 +59,22 @@ public static function evaluateDataProvider(): array
6459
'loose array subset and ArrayObject other' => [
6560
'expected' => true,
6661
'subset' => ['bar' => 0],
67-
'other' => new ArrayObject(['foo' => '', 'bar' => '0']),
62+
'other' => new \ArrayObject(['foo' => '', 'bar' => '0']),
6863
'strict' => false,
6964
],
7065
'strict ArrayObject subset and array other' => [
7166
'expected' => true,
72-
'subset' => new ArrayObject(['bar' => 0]),
67+
'subset' => new \ArrayObject(['bar' => 0]),
7368
'other' => ['foo' => '', 'bar' => 0],
7469
'strict' => true,
7570
],
7671
];
7772
}
7873

7974
/**
80-
* @param array|Traversable|mixed[] $subset
81-
* @param array|Traversable|mixed[] $other
82-
* @param bool $strict
75+
* @param array|\Traversable|mixed[] $subset
76+
* @param array|\Traversable|mixed[] $other
77+
* @param bool $strict
8378
*
8479
* @throws ExpectationFailedException
8580
* @throws InvalidArgumentException
@@ -118,20 +113,20 @@ public function testEvaluateFailMessage(): void
118113

119114
public function testIsCountable(): void
120115
{
121-
$reflection = new ReflectionClass(ArraySubset::class);
116+
$reflection = new \ReflectionClass(ArraySubset::class);
122117

123118
$this->assertTrue(
124-
$reflection->implementsInterface(Countable::class),
119+
$reflection->implementsInterface(\Countable::class),
125120
sprintf(
126121
'Failed to assert that ArraySubset implements "%s".',
127-
Countable::class
122+
\Countable::class
128123
)
129124
);
130125
}
131126

132127
public function testIsSelfDescribing(): void
133128
{
134-
$reflection = new ReflectionClass(ArraySubset::class);
129+
$reflection = new \ReflectionClass(ArraySubset::class);
135130

136131
$this->assertTrue(
137132
$reflection->implementsInterface(SelfDescribing::class),

tests/Fixtures/ArrayAccessible.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Tests\Fixtures;
15+
16+
class ArrayAccessible implements \ArrayAccess, \IteratorAggregate
17+
{
18+
private $array;
19+
20+
public function __construct(array $array = [])
21+
{
22+
$this->array = $array;
23+
}
24+
25+
public function offsetExists($offset)
26+
{
27+
return \array_key_exists($offset, $this->array);
28+
}
29+
30+
public function offsetGet($offset)
31+
{
32+
return $this->array[$offset];
33+
}
34+
35+
public function offsetSet($offset, $value): void
36+
{
37+
if (null === $offset) {
38+
$this->array[] = $value;
39+
} else {
40+
$this->array[$offset] = $value;
41+
}
42+
}
43+
44+
public function offsetUnset($offset): void
45+
{
46+
unset($this->array[$offset]);
47+
}
48+
49+
public function getIterator()
50+
{
51+
return new \ArrayIterator($this->array);
52+
}
53+
}

0 commit comments

Comments
 (0)