WhitespacesFixerConfigTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests;
  12. use PhpCsFixer\WhitespacesFixerConfig;
  13. /**
  14. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  15. *
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\WhitespacesFixerConfig
  19. */
  20. final class WhitespacesFixerConfigTest extends TestCase
  21. {
  22. /**
  23. * @param string $indent
  24. * @param string $lineEnding
  25. * @param null|string $exceptionRegExp
  26. *
  27. * @dataProvider provideTestCases
  28. */
  29. public function testCases($indent, $lineEnding, $exceptionRegExp = null)
  30. {
  31. if (null !== $exceptionRegExp) {
  32. $this->expectException(\InvalidArgumentException::class);
  33. $this->expectExceptionMessageRegExp('%^'.preg_quote($exceptionRegExp, '%').'$%');
  34. }
  35. $config = new WhitespacesFixerConfig($indent, $lineEnding);
  36. static::assertSame($indent, $config->getIndent());
  37. static::assertSame($lineEnding, $config->getLineEnding());
  38. }
  39. public function provideTestCases()
  40. {
  41. return [
  42. [' ', "\n"],
  43. ["\t", "\n"],
  44. [' ', "\r\n"],
  45. ["\t", "\r\n"],
  46. [' ', 'asd', 'Invalid "lineEnding" param, expected "\n" or "\r\n".'],
  47. [' ', [], 'Invalid "lineEnding" param, expected "\n" or "\r\n".'],
  48. ['std', "\n", 'Invalid "indent" param, expected tab or two or four spaces.'],
  49. [[], "\n", 'Invalid "indent" param, expected tab or two or four spaces.'],
  50. ];
  51. }
  52. }