NoSpacesInsideParenthesisFixerTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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\Whitespace;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. /**
  14. * @author Marc Aubé
  15. *
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Fixer\Whitespace\NoSpacesInsideParenthesisFixer
  19. */
  20. final class NoSpacesInsideParenthesisFixerTest extends AbstractFixerTestCase
  21. {
  22. /**
  23. * @param string $expected
  24. * @param null|string $input
  25. *
  26. * @dataProvider provideFixCases
  27. */
  28. public function testFix($expected, $input = null)
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. public function testLeaveNewLinesAlone()
  33. {
  34. $expected = <<<'EOF'
  35. <?php
  36. class Foo
  37. {
  38. private function bar()
  39. {
  40. if (foo(
  41. 'foo' ,
  42. 'bar' ,
  43. [1, 2, 3],
  44. 'baz' // a comment just to mix things up
  45. )) {
  46. return 1;
  47. };
  48. }
  49. }
  50. EOF;
  51. $this->doTest($expected);
  52. }
  53. public function provideFixCases()
  54. {
  55. return [
  56. [
  57. '<?php foo();',
  58. '<?php foo( );',
  59. ],
  60. [
  61. '<?php
  62. if (true) {
  63. // if body
  64. }',
  65. '<?php
  66. if ( true ) {
  67. // if body
  68. }',
  69. ],
  70. [
  71. '<?php
  72. if (true) {
  73. // if body
  74. }',
  75. '<?php
  76. if ( true ) {
  77. // if body
  78. }',
  79. ],
  80. [
  81. '<?php
  82. function foo($bar, $baz)
  83. {
  84. // function body
  85. }',
  86. '<?php
  87. function foo( $bar, $baz )
  88. {
  89. // function body
  90. }',
  91. ],
  92. [
  93. '<?php
  94. $foo->bar($arg1, $arg2);',
  95. '<?php
  96. $foo->bar( $arg1, $arg2 );',
  97. ],
  98. [
  99. '<?php
  100. $var = array( 1, 2, 3 );
  101. ',
  102. ],
  103. [
  104. '<?php
  105. $var = [ 1, 2, 3 ];
  106. ',
  107. ],
  108. // list call with trailing comma - need to leave alone
  109. [
  110. '<?php list($path, $mode, ) = foo();',
  111. ],
  112. [
  113. '<?php list($path, $mode,) = foo();',
  114. ],
  115. [
  116. '<?php
  117. $a = $b->test( // do not remove space
  118. $e // between `(` and `)`
  119. // and this comment
  120. );',
  121. ],
  122. ];
  123. }
  124. }