WhitespacesFixerConfigTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. use PHPUnit\Framework\TestCase;
  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 string $indent
  25. * @param string $lineEnding
  26. * @param null|string $exceptionRegExp
  27. *
  28. * @dataProvider provideTestCases
  29. */
  30. public function testCases($indent, $lineEnding, $exceptionRegExp = null)
  31. {
  32. if (null !== $exceptionRegExp) {
  33. $this->setExpectedExceptionRegExp(
  34. \InvalidArgumentException::class,
  35. '%^'.preg_quote($exceptionRegExp, '%').'$%'
  36. );
  37. }
  38. $config = new WhitespacesFixerConfig($indent, $lineEnding);
  39. $this->assertSame($indent, $config->getIndent());
  40. $this->assertSame($lineEnding, $config->getLineEnding());
  41. }
  42. public function provideTestCases()
  43. {
  44. return [
  45. [' ', "\n"],
  46. ["\t", "\n"],
  47. [' ', "\r\n"],
  48. ["\t", "\r\n"],
  49. [' ', 'asd', 'Invalid "lineEnding" param, expected "\n" or "\r\n".'],
  50. [' ', [], 'Invalid "lineEnding" param, expected "\n" or "\r\n".'],
  51. ['std', "\n", 'Invalid "indent" param, expected tab or two or four spaces.'],
  52. [[], "\n", 'Invalid "indent" param, expected tab or two or four spaces.'],
  53. ];
  54. }
  55. }