WhitespacesFixerConfigTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $indent, string $lineEnding, ?string $exceptionRegExp = null): void
  27. {
  28. if (null !== $exceptionRegExp) {
  29. $this->expectException(\InvalidArgumentException::class);
  30. $this->expectExceptionMessageMatches('%^'.preg_quote($exceptionRegExp, '%').'$%');
  31. }
  32. $config = new WhitespacesFixerConfig($indent, $lineEnding);
  33. self::assertSame($indent, $config->getIndent());
  34. self::assertSame($lineEnding, $config->getLineEnding());
  35. }
  36. /**
  37. * @return iterable<array{0: string, 1: string, 2?: string}>
  38. */
  39. public static function provideFixCases(): iterable
  40. {
  41. yield [' ', "\n"];
  42. yield ["\t", "\n"];
  43. yield [' ', "\r\n"];
  44. yield ["\t", "\r\n"];
  45. yield [' ', 'asd', 'Invalid "lineEnding" param, expected "\n" or "\r\n".'];
  46. yield ['std', "\n", 'Invalid "indent" param, expected tab or two or four spaces.'];
  47. }
  48. }