DeclareEqualNormalizeFixerTest.php 3.3 KB

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