IndentationFixerTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 Dariusz Rumiński <dariusz.ruminski@gmail.com>
  14. */
  15. class IndentationFixerTest extends AbstractFixerTestBase
  16. {
  17. /**
  18. * @dataProvider provideIndentationOnly
  19. */
  20. public function testIndentationOnly($expected, $input = null)
  21. {
  22. $this->makeTest($expected, $input);
  23. }
  24. /**
  25. * @dataProvider provideIndentationAndAlignment
  26. */
  27. public function testIndentationAndAlignment($expected, $input = null)
  28. {
  29. $this->makeTest($expected, $input);
  30. }
  31. /**
  32. * @dataProvider provideTabInString
  33. */
  34. public function testTabInString($expected, $input = null)
  35. {
  36. $this->makeTest($expected, $input);
  37. }
  38. /**
  39. * @dataProvider provideTabInComment
  40. */
  41. public function testTabInComment($expected, $input = null)
  42. {
  43. $this->makeTest($expected, $input);
  44. }
  45. public function provideIndentationOnly()
  46. {
  47. $cases = array();
  48. $cases[] = array(
  49. '<?php
  50. echo ALPHA;',
  51. "<?php
  52. \t\techo ALPHA;",
  53. );
  54. $cases[] = array(
  55. '<?php
  56. echo BRAVO;',
  57. "<?php
  58. \t\techo BRAVO;",
  59. );
  60. $cases[] = array(
  61. '<?php
  62. echo CHARLIE;',
  63. "<?php
  64. \t\techo CHARLIE;",
  65. );
  66. $cases[] = array(
  67. '<?php
  68. echo DELTA;',
  69. "<?php
  70. \t\techo DELTA;",
  71. );
  72. $cases[] = array(
  73. "<?php
  74. echo 'ECHO';",
  75. "<?php
  76. \t\techo 'ECHO';",
  77. );
  78. $cases[] = array(
  79. '<?php
  80. echo FOXTROT;',
  81. "<?php
  82. \t \techo FOXTROT;",
  83. );
  84. $cases[] = array(
  85. '<?php
  86. echo GOLF;',
  87. "<?php
  88. \t \techo GOLF;",
  89. );
  90. $cases[] = array(
  91. '<?php
  92. echo HOTEL;',
  93. "<?php
  94. \t \techo HOTEL;",
  95. );
  96. $cases[] = array(
  97. '<?php
  98. echo INDIA;',
  99. "<?php
  100. \t echo INDIA;",
  101. );
  102. $cases[] = array(
  103. '<?php
  104. echo JULIET;',
  105. "<?php
  106. \t \techo JULIET;",
  107. );
  108. $cases[] = array(
  109. '<?php
  110. echo KILO;',
  111. "<?php
  112. \t \techo KILO;",
  113. );
  114. $cases[] = array(
  115. '<?php
  116. echo MIKE;',
  117. "<?php
  118. \t \techo MIKE;",
  119. );
  120. $cases[] = array(
  121. '<?php
  122. echo NOVEMBER;',
  123. "<?php
  124. \techo NOVEMBER;",
  125. );
  126. return $cases;
  127. }
  128. public function provideIndentationAndAlignment()
  129. {
  130. $cases = array();
  131. $cases[] = array(
  132. '<?php
  133. echo OSCAR;',
  134. "<?php
  135. \t \t echo OSCAR;",
  136. );
  137. $cases[] = array(
  138. '<?php
  139. echo PAPA;',
  140. "<?php
  141. \t \t echo PAPA;",
  142. );
  143. $cases[] = array(
  144. '<?php
  145. echo QUEBEC;',
  146. "<?php
  147. \t \t echo QUEBEC;",
  148. );
  149. return $cases;
  150. }
  151. public function provideTabInString()
  152. {
  153. return array(
  154. array(
  155. '<?php $x = "a: \t";',
  156. ),
  157. array(
  158. "<?php
  159. \$x = \"
  160. \tLike
  161. \ta
  162. \tdog\";",
  163. ),
  164. );
  165. }
  166. public function provideTabInComment()
  167. {
  168. $cases = array();
  169. $cases[] = array(
  170. '<?php
  171. /**
  172. * Test that tabs in docblocks are converted to spaces.
  173. *
  174. * @test
  175. *
  176. * @return
  177. */',
  178. "<?php
  179. \t/**
  180. \t * Test that tabs in docblocks are converted to spaces.
  181. \t *
  182. \t * @test
  183. \t *
  184. \t * @return
  185. \t */",
  186. );
  187. $cases[] = array(
  188. '<?php
  189. /**
  190. * Test that tabs in docblocks are converted to spaces.
  191. */',
  192. "<?php
  193. \t\t/**
  194. \t\t * Test that tabs in docblocks are converted to spaces.
  195. \t\t */",
  196. );
  197. $cases[] = array(
  198. '<?php
  199. /*
  200. | Test that tabs in comments are converted to spaces.
  201. */',
  202. "<?php
  203. \t/*
  204. \t | Test that tabs in comments are converted to spaces.
  205. \t */",
  206. );
  207. $cases[] = array(
  208. "<?php
  209. /**
  210. * This variable
  211. * should not be '\t', really!
  212. */",
  213. "<?php
  214. \t/**
  215. \t * This variable
  216. \t * should not be '\t', really!
  217. \t */",
  218. );
  219. return $cases;
  220. }
  221. /**
  222. * @dataProvider provideTabInInlineHTML
  223. */
  224. public function testTabInInlineHTML($expected, $input = null)
  225. {
  226. $this->makeTest($expected, $input);
  227. }
  228. public function provideTabInInlineHTML()
  229. {
  230. $cases = array(
  231. array(
  232. "<?php\necho 1;\n?>\r\n\t\$a = ellow;",
  233. ),
  234. );
  235. return $cases;
  236. }
  237. }