DeprecatedFixerOptionTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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\DeprecatedFixerOption;
  14. use PhpCsFixer\FixerConfiguration\DeprecatedFixerOptionInterface;
  15. use PhpCsFixer\FixerConfiguration\FixerOption;
  16. use PhpCsFixer\FixerConfiguration\FixerOptionInterface;
  17. use PhpCsFixer\Tests\TestCase;
  18. /**
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\FixerConfiguration\DeprecatedFixerOption
  22. */
  23. final class DeprecatedFixerOptionTest extends TestCase
  24. {
  25. public function testConstruct(): void
  26. {
  27. $option = new DeprecatedFixerOption(
  28. new FixerOption('foo', 'Foo.'),
  29. 'deprecated'
  30. );
  31. self::assertInstanceOf(FixerOptionInterface::class, $option);
  32. self::assertInstanceOf(DeprecatedFixerOptionInterface::class, $option);
  33. }
  34. public function testGetName(): void
  35. {
  36. $option = new DeprecatedFixerOption(
  37. new FixerOption('foo', 'Foo.'),
  38. 'deprecated'
  39. );
  40. self::assertSame('foo', $option->getName());
  41. }
  42. public function testGetDescription(): void
  43. {
  44. $option = new DeprecatedFixerOption(
  45. new FixerOption('foo', 'Foo.'),
  46. 'deprecated'
  47. );
  48. self::assertSame('Foo.', $option->getDescription());
  49. }
  50. /**
  51. * @dataProvider provideHasDefaultCases
  52. */
  53. public function testHasDefault(bool $isRequired): void
  54. {
  55. $option = new DeprecatedFixerOption(
  56. new FixerOption('foo', 'Foo.', $isRequired),
  57. 'deprecated'
  58. );
  59. self::assertSame(!$isRequired, $option->hasDefault());
  60. }
  61. public static function provideHasDefaultCases(): iterable
  62. {
  63. yield [true];
  64. yield [false];
  65. }
  66. /**
  67. * @param mixed $default
  68. *
  69. * @dataProvider provideGetDefaultCases
  70. */
  71. public function testGetDefault($default): void
  72. {
  73. $option = new DeprecatedFixerOption(
  74. new FixerOption('foo', 'Foo.', false, $default),
  75. 'deprecated'
  76. );
  77. self::assertSame($default, $option->getDefault());
  78. }
  79. public static function provideGetDefaultCases(): iterable
  80. {
  81. yield ['foo'];
  82. yield [true];
  83. }
  84. public function testGetAllowedTypes(): void
  85. {
  86. $allowedTypes = ['string', 'bool'];
  87. $option = new DeprecatedFixerOption(
  88. new FixerOption('foo', 'Foo.', true, null, $allowedTypes),
  89. 'deprecated'
  90. );
  91. self::assertSame($allowedTypes, $option->getAllowedTypes());
  92. }
  93. public function testGetAllowedValues(): void
  94. {
  95. $allowedValues = ['string', 'bool'];
  96. $option = new DeprecatedFixerOption(
  97. new FixerOption('foo', 'Foo.', true, null, [], $allowedValues),
  98. 'deprecated'
  99. );
  100. self::assertSame($allowedValues, $option->getAllowedValues());
  101. }
  102. public function testGetNormalizer(): void
  103. {
  104. $normalizer = static fn () => null;
  105. $decoratedOption = $this->prophesize(FixerOptionInterface::class);
  106. $decoratedOption->getNormalizer()->willReturn($normalizer);
  107. $option = new DeprecatedFixerOption(
  108. $decoratedOption->reveal(),
  109. 'deprecated'
  110. );
  111. self::assertSame($normalizer, $option->getNormalizer());
  112. }
  113. public function testGetDeprecationMessage(): void
  114. {
  115. $option = new DeprecatedFixerOption(
  116. new FixerOption('foo', 'Foo.'),
  117. 'Use option "bar" instead.'
  118. );
  119. self::assertSame('Use option "bar" instead.', $option->getDeprecationMessage());
  120. }
  121. }