WhitespacesFixerConfigTest.php 1.8 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',
  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 array(
  45. array(' ', "\n"),
  46. array("\t", "\n"),
  47. array(' ', "\r\n"),
  48. array("\t", "\r\n"),
  49. array(' ', 'asd', 'Invalid "lineEnding" param, expected "\n" or "\r\n".'),
  50. array(' ', array(), 'Invalid "lineEnding" param, expected "\n" or "\r\n".'),
  51. array('std', "\n", 'Invalid "indent" param, expected tab or two or four spaces.'),
  52. array(array(), "\n", 'Invalid "indent" param, expected tab or two or four spaces.'),
  53. );
  54. }
  55. }