Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(metadata): Operations priority sort (#6206)
* fix(metadata): fix Operations sort * test: priority test --------- Co-authored-by: soyuka <soyuka@users.noreply.github.com>
- Loading branch information
1 parent
055fb38
commit 98f4b8f
Showing
9 changed files
with
93 additions
and
5 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
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,36 @@ | ||
<?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\Metadata\Tests; | ||
|
||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Metadata\Operations; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class OperationsTest extends TestCase | ||
{ | ||
public function testOperationsHaveNameIfNotSet(): void | ||
{ | ||
$operations = new Operations([new Get(name: 'a'), new Get(name: 'b')]); | ||
|
||
foreach ($operations as $name => $operation) { | ||
$this->assertEquals($name, $operation->getName()); | ||
} | ||
} | ||
|
||
public function testOperationAreSorted(): void | ||
{ | ||
$operations = new Operations(['a' => new Get(priority: 0), 'b' => new Get(priority: -1)]); | ||
$this->assertEquals(['b', 'a'], array_keys(iterator_to_array($operations))); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/Fixtures/TestBundle/ApiResource/OperationPriorities.php
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,33 @@ | ||
<?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\Tests\Fixtures\TestBundle\ApiResource; | ||
|
||
use ApiPlatform\Metadata\Get; | ||
|
||
#[Get(name: 'a', priority: 1, uriTemplate: 'operation_priority/{id}', provider: [self::class, 'shouldNotBeCalled'])] | ||
#[Get(name: 'b', priority: -1, uriTemplate: 'operation_priority/{id}', provider: [self::class, 'shouldBeCalled'])] | ||
class OperationPriorities | ||
{ | ||
public int $id = 1; | ||
|
||
public static function shouldBeCalled(): self | ||
{ | ||
return new self(); | ||
} | ||
|
||
public static function shouldNotBeCalled(): self | ||
{ | ||
throw new \Exception('fail'); | ||
} | ||
} |
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