FixerOptionSorterTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\FixerConfiguration;
  13. use PhpCsFixer\FixerConfiguration\FixerOption;
  14. use PhpCsFixer\FixerConfiguration\FixerOptionSorter;
  15. use PhpCsFixer\Tests\TestCase;
  16. /**
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\FixerConfiguration\FixerOptionSorter
  20. */
  21. final class FixerOptionSorterTest extends TestCase
  22. {
  23. public function testSortAcceptsEmptyArray(): void
  24. {
  25. $unsorted = [];
  26. $sorter = new FixerOptionSorter();
  27. $expected = [];
  28. self::assertSame($expected, $sorter->sort($unsorted));
  29. }
  30. public function testSortSortsArrayOfOptionsByName(): void
  31. {
  32. $fooOption = new FixerOption('foo', 'Bar.');
  33. $bazOption = new FixerOption('baz', 'Qux.');
  34. $unsorted = [
  35. $fooOption,
  36. $bazOption,
  37. ];
  38. $sorter = new FixerOptionSorter();
  39. $expected = [
  40. $bazOption,
  41. $fooOption,
  42. ];
  43. self::assertSame($expected, $sorter->sort($unsorted));
  44. }
  45. public function testSortAcceptsEmptyIterable(): void
  46. {
  47. $unsorted = new \ArrayIterator();
  48. $sorter = new FixerOptionSorter();
  49. $expected = [];
  50. self::assertSame($expected, $sorter->sort($unsorted));
  51. }
  52. public function testSortSortsIterableOfOptionsByName(): void
  53. {
  54. $fooOption = new FixerOption('foo', 'Bar.');
  55. $bazOption = new FixerOption('baz', 'Qux.');
  56. $unsorted = new \ArrayIterator([
  57. $fooOption,
  58. $bazOption,
  59. ]);
  60. $sorter = new FixerOptionSorter();
  61. $expected = [
  62. $bazOption,
  63. $fooOption,
  64. ];
  65. self::assertSame($expected, $sorter->sort($unsorted));
  66. }
  67. }