-
-
Notifications
You must be signed in to change notification settings - Fork 849
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GraphQL] Fix filter arguments order (#3468)
* add behat test on graphql order filter arguments order * change graphql filter type to preserve argument order * extract array related function into an utility class * update test * fix CS * feat: add a deprecated message when using the old filter syntax * fix: minor fixes * chore: add CHANGELOG entry Co-authored-by: Alan Poulain <contact@alanpoulain.eu>
- Loading branch information
1 parent
68163f3
commit b322aff
Showing
10 changed files
with
232 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* 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\Util; | ||
|
||
trait ArrayTrait | ||
{ | ||
public function isSequentialArrayOfArrays(array $array): bool | ||
{ | ||
if (!$this->isSequentialArray($array)) { | ||
return false; | ||
} | ||
|
||
return $this->arrayContainsOnly($array, 'array'); | ||
} | ||
|
||
public function isSequentialArray(array $array): bool | ||
{ | ||
if ([] === $array) { | ||
return false; | ||
} | ||
|
||
return array_keys($array) === range(0, \count($array) - 1); | ||
} | ||
|
||
public function arrayContainsOnly(array $array, string $type): bool | ||
{ | ||
return $array === array_filter($array, static function ($item) use ($type): bool { | ||
return $type === \gettype($item); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* 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\Util; | ||
|
||
use ApiPlatform\Core\Util\ArrayTrait; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ArrayTraitTest extends TestCase | ||
{ | ||
private $arrayTraitClass; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->arrayTraitClass = (new class() { | ||
use ArrayTrait; | ||
}); | ||
} | ||
|
||
public function testIsSequentialArrayWithEmptyArray(): void | ||
{ | ||
self::assertFalse($this->arrayTraitClass->isSequentialArray([])); | ||
} | ||
|
||
public function testIsSequentialArrayWithNonNumericIndex(): void | ||
{ | ||
self::assertFalse($this->arrayTraitClass->isSequentialArray(['foo' => 'bar'])); | ||
} | ||
|
||
public function testIsSequentialArrayWithNumericNonSequentialIndex(): void | ||
{ | ||
self::assertFalse($this->arrayTraitClass->isSequentialArray([1 => 'bar', 3 => 'foo'])); | ||
} | ||
|
||
public function testIsSequentialArrayWithNumericSequentialIndex(): void | ||
{ | ||
self::assertTrue($this->arrayTraitClass->isSequentialArray([0 => 'bar', 1 => 'foo'])); | ||
} | ||
|
||
public function testArrayContainsOnlyWithDifferentTypes(): void | ||
{ | ||
self::assertFalse($this->arrayTraitClass->arrayContainsOnly([1, 'foo'], 'string')); | ||
} | ||
|
||
public function testArrayContainsOnlyWithSameType(): void | ||
{ | ||
self::assertTrue($this->arrayTraitClass->arrayContainsOnly(['foo', 'bar'], 'string')); | ||
} | ||
|
||
public function testIsSequentialArrayOfArrays(): void | ||
{ | ||
self::assertFalse($this->arrayTraitClass->isSequentialArrayOfArrays([])); | ||
self::assertTrue($this->arrayTraitClass->isSequentialArrayOfArrays([['foo'], ['bar']])); | ||
} | ||
} |