FixerOptionBuilderTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\FixerOption;
  15. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  16. use PhpCsFixer\Tests\TestCase;
  17. /**
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\FixerConfiguration\FixerOptionBuilder
  21. */
  22. final class FixerOptionBuilderTest extends TestCase
  23. {
  24. public function testSetDefault(): void
  25. {
  26. $builder = new FixerOptionBuilder('foo', 'Bar.');
  27. self::assertSame($builder, $builder->setDefault('baz'));
  28. }
  29. public function testSetAllowedTypes(): void
  30. {
  31. $builder = new FixerOptionBuilder('foo', 'Bar.');
  32. self::assertSame($builder, $builder->setAllowedTypes(['bool']));
  33. }
  34. public function testSetAllowedValues(): void
  35. {
  36. $builder = new FixerOptionBuilder('foo', 'Bar.');
  37. self::assertSame($builder, $builder->setAllowedValues(['baz']));
  38. }
  39. public function testSetNormalizer(): void
  40. {
  41. $builder = new FixerOptionBuilder('foo', 'Bar.');
  42. self::assertSame($builder, $builder->setNormalizer(static fn () => null));
  43. }
  44. public function testGetOption(): void
  45. {
  46. $builder = new FixerOptionBuilder('foo', 'Bar.');
  47. $regularOption = $builder
  48. ->setDefault('baz')
  49. ->setAllowedTypes(['bool'])
  50. ->setAllowedValues([true, false])
  51. ->setNormalizer(static fn () => null)
  52. ->getOption()
  53. ;
  54. self::assertInstanceOf(FixerOption::class, $regularOption);
  55. $deprecationOption = $builder
  56. ->setDefault('baz')
  57. ->setAllowedTypes(['bool'])
  58. ->setAllowedValues([true, false])
  59. ->setNormalizer(static fn () => null)
  60. ->setDeprecationMessage('Deprecation message')
  61. ->getOption()
  62. ;
  63. self::assertInstanceOf(DeprecatedFixerOption::class, $deprecationOption);
  64. foreach ([$regularOption, $deprecationOption] as $option) {
  65. self::assertSame('foo', $option->getName());
  66. self::assertSame('Bar.', $option->getDescription());
  67. self::assertTrue($option->hasDefault());
  68. self::assertSame('baz', $option->getDefault());
  69. self::assertSame(['bool'], $option->getAllowedTypes());
  70. self::assertSame([true, false], $option->getAllowedValues());
  71. self::assertInstanceOf(\Closure::class, $option->getNormalizer());
  72. }
  73. }
  74. }