MethodArgumentSpaceFixerTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /*
  3. * This file is part of the PHP CS utility.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\CS\Tests\Fixer\PSR2;
  11. use Symfony\CS\Tests\Fixer\AbstractFixerTestBase;
  12. /**
  13. * @author Kuanhung Chen <ericj.tw@gmail.com>
  14. */
  15. class MethodArgumentSpaceFixerTest extends AbstractFixerTestBase
  16. {
  17. /**
  18. * @dataProvider testFixProvider
  19. */
  20. public function testFix($expected, $input = null)
  21. {
  22. $this->makeTest($expected, $input);
  23. }
  24. public function testFixProvider()
  25. {
  26. return array(
  27. // test method arguments
  28. array(
  29. '<?php function xyz($a=10, $b=20, $c=30) {}',
  30. '<?php function xyz($a=10,$b=20,$c=30) {}',
  31. ),
  32. // test method call
  33. array(
  34. '<?php xyz($a=10, $b=20, $c=30);',
  35. '<?php xyz($a=10 ,$b=20,$c=30);',
  36. ),
  37. // test method call
  38. array(
  39. '<?php xyz($a=10, $b=20, $this->foo(), $c=30);',
  40. '<?php xyz($a=10,$b=20 ,$this->foo() ,$c=30);',
  41. ),
  42. // test receiving data in list context with omitted values
  43. array(
  44. '<?php list($a, $b, , , $c) = foo();',
  45. '<?php list($a, $b,, ,$c) = foo();',
  46. ),
  47. // skip array
  48. array(
  49. '<?php array(10 , 20 ,30);',
  50. ),
  51. // list call with trailing comma
  52. array(
  53. '<?php list($path, $mode, ) = foo();',
  54. '<?php list($path, $mode,) = foo();',
  55. ),
  56. // multi line testing method arguments
  57. array(
  58. '<?php function xyz(
  59. $a=10,
  60. $b=20,
  61. $c=30) {
  62. }',
  63. '<?php function xyz(
  64. $a=10 ,
  65. $b=20,
  66. $c=30) {
  67. }',
  68. ),
  69. // multi line testing method call
  70. array(
  71. '<?php xyz(
  72. $a=10,
  73. $b=20,
  74. $c=30
  75. );',
  76. '<?php xyz(
  77. $a=10 ,
  78. $b=20,
  79. $c=30
  80. );',
  81. ),
  82. // skip multi line array
  83. array(
  84. '<?php
  85. array(
  86. 10 ,
  87. 20,
  88. 30
  89. );',
  90. ),
  91. // skip short array
  92. array(
  93. '<?php
  94. $foo = ["a"=>"apple", "b"=>"bed" ,"c"=>"car"];
  95. $foo = ["a" ,"b" ,"c"];
  96. ',
  97. ),
  98. // don't change HEREDOC and NOWDOC
  99. array(
  100. "<?php
  101. \$this->foo(
  102. <<<EOTXTa
  103. heredoc
  104. EOTXTa
  105. ,
  106. <<<'EOTXTb'
  107. nowdoc
  108. EOTXTb
  109. ,
  110. 'foo'
  111. );
  112. ",
  113. ),
  114. );
  115. }
  116. }