Skip to content

Commit

Permalink
Merge pull request #1296 from gam6itko/custom_accessor_order
Browse files Browse the repository at this point in the history
add missing CustomPropertyOrderingStrategyTest
  • Loading branch information
goetas authored Mar 18, 2021
2 parents 4b400e3 + a19d868 commit 8a98bf2
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/Ordering/CustomPropertyOrderingStrategyTest.php
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'],
];
}
}

0 comments on commit 8a98bf2

Please sign in to comment.