ConcatSpaceFixerTest.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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\Operator;
  12. use PhpCsFixer\Test\AbstractFixerTestCase;
  13. /**
  14. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  15. * @author SpacePossum
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Operator\ConcatSpaceFixer
  20. */
  21. final class ConcatSpaceFixerTest extends AbstractFixerTestCase
  22. {
  23. public function testInvalidConfigMissingKey()
  24. {
  25. $this->setExpectedExceptionRegExp(
  26. \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class,
  27. '#^\[concat_space\] Invalid configuration: The option "a" does not exist\. Defined options are: "spacing"\.$#'
  28. );
  29. $this->fixer->configure(['a' => 1]);
  30. }
  31. public function testInvalidConfigValue()
  32. {
  33. $this->setExpectedExceptionRegExp(
  34. \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class,
  35. '#^\[concat_space\] Invalid configuration: The option "spacing" with value "tabs" is invalid\. Accepted values are: "one", "none"\.$#'
  36. );
  37. $this->fixer->configure(['spacing' => 'tabs']);
  38. }
  39. /**
  40. * @param string $expected
  41. * @param null|string $input
  42. *
  43. * @dataProvider provideWithoutSpaceCases
  44. */
  45. public function testFixWithoutSpace($expected, $input = null)
  46. {
  47. $this->fixer->configure(['spacing' => 'none']);
  48. $this->doTest($expected, $input);
  49. }
  50. public function provideWithoutSpaceCases()
  51. {
  52. return [
  53. [
  54. '<?php $foo = "a".\'b\'."c"."d".$e.($f + 1);',
  55. '<?php $foo = "a" . \'b\' ."c". "d" . $e.($f + 1);',
  56. ],
  57. [
  58. '<?php $foo = 1 ."foo";',
  59. '<?php $foo = 1 . "foo";',
  60. ],
  61. [
  62. '<?php $foo = "foo". 1;',
  63. '<?php $foo = "foo" . 1;',
  64. ],
  65. [
  66. '<?php $foo = "a".
  67. "b";',
  68. '<?php $foo = "a" .
  69. "b";',
  70. ],
  71. [
  72. '<?php $a = "foobar"
  73. ."baz";',
  74. ],
  75. [
  76. '<?php $a = "foobar"
  77. //test
  78. ."baz";',
  79. ],
  80. [
  81. '<?php $a = "foobar"
  82. /* test */
  83. ."baz";',
  84. ],
  85. [
  86. '<?php $a = "foobar" //
  87. ."baz";',
  88. ],
  89. [
  90. '<?php $a = "foobar" //
  91. ."baz"//
  92. ."cex"/**/
  93. ."dev"/** */
  94. ."baz" //
  95. ."cex" /**/
  96. ."ewer23" '.'
  97. ."dev" /** */
  98. ;',
  99. ],
  100. [
  101. '<?php $a = "foobar" //
  102. ."baz" /**/
  103. ."something";',
  104. ],
  105. [
  106. '<?php $a = "foobar"
  107. ."baz". //
  108. "something";',
  109. ],
  110. [
  111. '<?php $a = "foobar"
  112. ."baz". /** */
  113. "something";',
  114. ],
  115. [
  116. "<?php
  117. \$longString = '*'
  118. .'*****'
  119. .'*****'
  120. .'*****'
  121. // Comment about next line
  122. .'*****'
  123. // Other comment
  124. .'*****';
  125. ",
  126. "<?php
  127. \$longString = '*'
  128. . '*****'
  129. . '*****'
  130. . '*****'
  131. // Comment about next line
  132. . '*****'
  133. // Other comment
  134. . '*****';
  135. ",
  136. ],
  137. ];
  138. }
  139. /**
  140. * @param string $expected
  141. * @param null|string $input
  142. *
  143. * @dataProvider provideWithSpaceCases
  144. */
  145. public function testFixWithSpace($expected, $input = null)
  146. {
  147. $this->fixer->configure(['spacing' => 'one']);
  148. $this->doTest($expected, $input);
  149. }
  150. public function provideWithSpaceCases()
  151. {
  152. return [
  153. [
  154. '<?php
  155. $a = //
  156. $c . /**/
  157. $d #
  158. . $e /** */
  159. . $f . //
  160. $z;
  161. ',
  162. '<?php
  163. $a = //
  164. $c . /**/
  165. $d #
  166. . $e /** */
  167. . $f . //
  168. $z;
  169. ',
  170. ],
  171. [
  172. '<?php $foo = "a" . \'b\' . "c" . "d" . $e . ($f + 1);',
  173. '<?php $foo = "a" . \'b\' ."c". "d" . $e.($f + 1);',
  174. ],
  175. [
  176. '<?php $foo = "a" .
  177. "b";',
  178. '<?php $foo = "a".
  179. "b";',
  180. ],
  181. [
  182. '<?php $a = "foobar"
  183. . "baz";',
  184. '<?php $a = "foobar"
  185. ."baz";',
  186. ],
  187. [
  188. '<?php echo $a . $b;
  189. echo $d . $e . //
  190. $f;
  191. echo $a . $b?>
  192. <?php
  193. echo $c;
  194. ',
  195. '<?php echo $a.$b;
  196. echo $d . $e . //
  197. $f;
  198. echo $a . $b?>
  199. <?php
  200. echo $c;
  201. ',
  202. ],
  203. ];
  204. }
  205. }