Skip to content

Do not rely on fixture from phpunit tests directory #2938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@
"autoload-dev": {
"psr-4": {
"ApiPlatform\\Core\\Tests\\": "tests/"
},
"classmap": [
"vendor/phpunit/phpunit/tests/"
]
}
},
"extra": {
"branch-alias": {
Expand Down
25 changes: 10 additions & 15 deletions tests/Bridge/Symfony/Bundle/Test/Constraint/ArraySubsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@
namespace ApiPlatform\Core\Tests\Bridge\Symfony\Bundle\Test\Constraint;

use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Constraint\ArraySubset;
use ArrayAccessible;
use ArrayObject;
use Countable;
use ApiPlatform\Core\Tests\Fixtures\ArrayAccessible;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\SelfDescribing;
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\Version;
use ReflectionClass;
use SebastianBergmann\RecursionContext\InvalidArgumentException;
use Traversable;
use function sprintf;

/**
* Imported from dms/phpunit-arraysubset-asserts, because the original constraint has been deprecated.
Expand Down Expand Up @@ -64,22 +59,22 @@ public static function evaluateDataProvider(): array
'loose array subset and ArrayObject other' => [
'expected' => true,
'subset' => ['bar' => 0],
'other' => new ArrayObject(['foo' => '', 'bar' => '0']),
'other' => new \ArrayObject(['foo' => '', 'bar' => '0']),
'strict' => false,
],
'strict ArrayObject subset and array other' => [
'expected' => true,
'subset' => new ArrayObject(['bar' => 0]),
'subset' => new \ArrayObject(['bar' => 0]),
'other' => ['foo' => '', 'bar' => 0],
'strict' => true,
],
];
}

/**
* @param array|Traversable|mixed[] $subset
* @param array|Traversable|mixed[] $other
* @param bool $strict
* @param array|\Traversable|mixed[] $subset
* @param array|\Traversable|mixed[] $other
* @param bool $strict
*
* @throws ExpectationFailedException
* @throws InvalidArgumentException
Expand Down Expand Up @@ -118,20 +113,20 @@ public function testEvaluateFailMessage(): void

public function testIsCountable(): void
{
$reflection = new ReflectionClass(ArraySubset::class);
$reflection = new \ReflectionClass(ArraySubset::class);

$this->assertTrue(
$reflection->implementsInterface(Countable::class),
$reflection->implementsInterface(\Countable::class),
sprintf(
'Failed to assert that ArraySubset implements "%s".',
Countable::class
\Countable::class
)
);
}

public function testIsSelfDescribing(): void
{
$reflection = new ReflectionClass(ArraySubset::class);
$reflection = new \ReflectionClass(ArraySubset::class);

$this->assertTrue(
$reflection->implementsInterface(SelfDescribing::class),
Expand Down
53 changes: 53 additions & 0 deletions tests/Fixtures/ArrayAccessible.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Core\Tests\Fixtures;

class ArrayAccessible implements \ArrayAccess, \IteratorAggregate
{
private $array;

public function __construct(array $array = [])
{
$this->array = $array;
}

public function offsetExists($offset)
{
return \array_key_exists($offset, $this->array);
}

public function offsetGet($offset)
{
return $this->array[$offset];
}

public function offsetSet($offset, $value): void
{
if (null === $offset) {
$this->array[] = $value;
} else {
$this->array[$offset] = $value;
}
}

public function offsetUnset($offset): void
{
unset($this->array[$offset]);
}

public function getIterator()
{
return new \ArrayIterator($this->array);
}
}