DeclareEqualNormalizeFixerTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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\Fixer\LanguageConstruct;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. /**
  14. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  15. * @author SpacePossum
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\LanguageConstruct\DeclareEqualNormalizeFixer
  20. */
  21. final class DeclareEqualNormalizeFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @param string $expected
  25. * @param string $input
  26. * @param array $config
  27. *
  28. * @dataProvider provideFixCases
  29. */
  30. public function testFix($expected, $input, array $config)
  31. {
  32. $this->fixer->configure($config);
  33. $this->doTest($expected, $input);
  34. }
  35. public function provideFixCases()
  36. {
  37. return [
  38. 'minimal case remove whitespace (default config)' => [
  39. '<?php declare(ticks=1);',
  40. '<?php declare(ticks= 1);',
  41. [],
  42. ],
  43. 'minimal case remove whitespace (no space config)' => [
  44. '<?php declare(ticks=1);',
  45. '<?php declare(ticks = 1);',
  46. ['space' => 'none'],
  47. ],
  48. 'minimal case add whitespace' => [
  49. '<?php declare(ticks = 1);',
  50. '<?php declare(ticks=1);',
  51. ['space' => 'single'],
  52. ],
  53. 'to much whitespace case add whitespace' => [
  54. '<?php declare(ticks = 1);',
  55. "<?php declare(ticks\n\t = 1);",
  56. ['space' => 'single'],
  57. ],
  58. 'repeating case remove whitespace (default config)' => [
  59. '<?php declare(ticks=1);declare(ticks=1)?>',
  60. '<?php declare(ticks= 1);declare(ticks= 1)?>',
  61. [],
  62. ],
  63. 'repeating case add whitespace' => [
  64. '<?php declare ( ticks = 1 );declare( ticks = 1) ?>',
  65. '<?php declare ( ticks=1 );declare( ticks =1) ?>',
  66. ['space' => 'single'],
  67. ],
  68. 'minimal case add whitespace comments, single' => [
  69. '<?php declare(ticks#
  70. = #
  71. 1#
  72. );',
  73. '<?php declare(ticks#
  74. =#
  75. 1#
  76. );',
  77. ['space' => 'single'],
  78. ],
  79. 'minimal case add whitespace comments, none' => [
  80. '<?php declare(ticks#
  81. =#
  82. 1#
  83. );',
  84. null,
  85. ['space' => 'none'],
  86. ],
  87. ];
  88. }
  89. /**
  90. * @param array $config
  91. * @param string $expectedMessage
  92. *
  93. * @dataProvider provideInvalidConfigCases
  94. */
  95. public function testInvalidConfig(array $config, $expectedMessage)
  96. {
  97. $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class);
  98. $this->expectExceptionMessage(sprintf('[declare_equal_normalize] Invalid configuration: %s', $expectedMessage));
  99. $this->fixer->configure($config);
  100. }
  101. public function provideInvalidConfigCases()
  102. {
  103. return [
  104. [
  105. [1, 2],
  106. 'The options "0", "1" do not exist.',
  107. ],
  108. [
  109. ['space' => 'tab'],
  110. 'The option "space" with value "tab" is invalid.',
  111. ],
  112. ];
  113. }
  114. }