AliasedFixerOptionBuilderTest.php 2.4 KB

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