-
-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1296 from gam6itko/custom_accessor_order
add missing CustomPropertyOrderingStrategyTest
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Tests\Ordering; | ||
|
||
use JMS\Serializer\Metadata\PropertyMetadata; | ||
use JMS\Serializer\Ordering\CustomPropertyOrderingStrategy; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CustomPropertyOrderingStrategyTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider dataOrder | ||
*/ | ||
public function testOrder(array $ordering, array $keysToSort, array $expectedResult): void | ||
{ | ||
$strategy = new CustomPropertyOrderingStrategy(array_flip($ordering)); | ||
|
||
$properties = array_combine( | ||
$keysToSort, | ||
array_pad([], count($keysToSort), $this->createMock(PropertyMetadata::class)) | ||
); | ||
$sortedProperties = $strategy->order($properties); | ||
self::assertEquals($expectedResult, array_keys($sortedProperties)); | ||
} | ||
|
||
public function dataOrder(): iterable | ||
{ | ||
$order = ['one', 'two', 'three']; | ||
|
||
yield [ | ||
$order, | ||
['three', 'two', 'one'], | ||
$order, | ||
]; | ||
|
||
$order = ['g', 'a', 'm', 'b', 'i', 't', 'k', 'o']; | ||
|
||
yield [ | ||
$order, | ||
['k', 'a', 'm', 'b', 'o', 'g', 'i', 't'], | ||
$order, | ||
]; | ||
|
||
yield [ | ||
['a', 'c', 'e', 'g', 'i', 'k', 'm', 't'], | ||
['f', 'e', 'd', 'c', 'b', 'a'], | ||
['a', 'c', 'e', 'f', 'd', 'b'], | ||
]; | ||
} | ||
} |