WhitespacesFixerConfigTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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;
  13. use PhpCsFixer\WhitespacesFixerConfig;
  14. /**
  15. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\WhitespacesFixerConfig
  20. */
  21. final class WhitespacesFixerConfigTest extends TestCase
  22. {
  23. /**
  24. * @param non-empty-string $indent
  25. * @param non-empty-string $lineEnding
  26. * @param ?non-empty-string $exceptionRegExp
  27. *
  28. * @dataProvider provideFixCases
  29. */
  30. public function testFix(string $indent, string $lineEnding, ?string $exceptionRegExp = null): void
  31. {
  32. if (null !== $exceptionRegExp) {
  33. $this->expectException(\InvalidArgumentException::class);
  34. $this->expectExceptionMessageMatches('%^'.preg_quote($exceptionRegExp, '%').'$%');
  35. }
  36. $config = new WhitespacesFixerConfig($indent, $lineEnding);
  37. self::assertSame($indent, $config->getIndent());
  38. self::assertSame($lineEnding, $config->getLineEnding());
  39. }
  40. /**
  41. * @return iterable<array{0: non-empty-string, 1: non-empty-string, 2?: non-empty-string}>
  42. */
  43. public static function provideFixCases(): iterable
  44. {
  45. yield [' ', "\n"];
  46. yield ["\t", "\n"];
  47. yield [' ', "\r\n"];
  48. yield ["\t", "\r\n"];
  49. yield [' ', 'asd', 'Invalid "lineEnding" param, expected "\n" or "\r\n".'];
  50. yield ['std', "\n", 'Invalid "indent" param, expected tab or two or four spaces.'];
  51. }
  52. }