WhitespacesFixerConfigTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. public static function provideFixCases(): iterable
  37. {
  38. yield [' ', "\n"];
  39. yield ["\t", "\n"];
  40. yield [' ', "\r\n"];
  41. yield ["\t", "\r\n"];
  42. yield [' ', 'asd', 'Invalid "lineEnding" param, expected "\n" or "\r\n".'];
  43. yield ['std', "\n", 'Invalid "indent" param, expected tab or two or four spaces.'];
  44. }
  45. }