PhpUnitSizeClassFixerTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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\PhpUnit;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. /**
  14. * @internal
  15. *
  16. * @author Jefersson Nathan <malukenho.dev@gmail.com>
  17. *
  18. * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitSizeClassFixer
  19. */
  20. final class PhpUnitSizeClassFixerTest extends AbstractFixerTestCase
  21. {
  22. /**
  23. * @dataProvider provideFixCases
  24. *
  25. * @param string $expected
  26. * @param null|mixed $input
  27. * @param array $config
  28. */
  29. public function testFix($expected, $input = null, $config = [])
  30. {
  31. $this->fixer->configure($config);
  32. $this->doTest($expected, $input);
  33. }
  34. public function provideFixCases()
  35. {
  36. return [
  37. 'It does not change normal classes' => [
  38. '<?php
  39. class Hello
  40. {
  41. }
  42. ',
  43. ],
  44. 'It marks a test class as @small by default' => [
  45. '<?php
  46. /**
  47. * @small
  48. */
  49. class Test extends TestCase
  50. {
  51. }
  52. ',
  53. '<?php
  54. class Test extends TestCase
  55. {
  56. }
  57. ',
  58. ],
  59. 'It marks a test class as specified in the configuration' => [
  60. '<?php
  61. /**
  62. * @large
  63. */
  64. class Test extends TestCase
  65. {
  66. }
  67. ',
  68. '<?php
  69. class Test extends TestCase
  70. {
  71. }
  72. ',
  73. ['group' => 'large'],
  74. ],
  75. 'It adds an @small tag to a class that already has a doc block' => [
  76. '<?php
  77. /**
  78. * @coversNothing
  79. *
  80. * @small
  81. */
  82. class Test extends TestCase
  83. {
  84. }
  85. ',
  86. '<?php
  87. /**
  88. * @coversNothing
  89. */
  90. class Test extends TestCase
  91. {
  92. }
  93. ',
  94. ],
  95. 'It does not change a class that is already @small' => [
  96. '<?php
  97. /**
  98. * @small
  99. */
  100. class Test extends TestCase
  101. {
  102. }
  103. ',
  104. ],
  105. 'It does not change a class that is already @small and has other annotations' => [
  106. '<?php
  107. /**
  108. * @author malukenho
  109. * @coversNothing
  110. * @large
  111. * @group large
  112. */
  113. class Test extends TestCase
  114. {
  115. }
  116. ',
  117. ],
  118. 'It works on other indentation levels' => [
  119. '<?php
  120. if (class_exists("Foo\Bar")) {
  121. /**
  122. * @small
  123. */
  124. class Test Extends TestCase
  125. {
  126. }
  127. }
  128. ',
  129. '<?php
  130. if (class_exists("Foo\Bar")) {
  131. class Test Extends TestCase
  132. {
  133. }
  134. }
  135. ',
  136. ],
  137. 'It works on other indentation levels when the class has other annotations' => [
  138. '<?php
  139. if (class_exists("Foo\Bar")) {
  140. /**
  141. * @author malukenho again
  142. *
  143. *
  144. * @covers \Other\Class
  145. *
  146. * @small
  147. */
  148. class Test Extends TestCase
  149. {
  150. }
  151. }
  152. ',
  153. '<?php
  154. if (class_exists("Foo\Bar")) {
  155. /**
  156. * @author malukenho again
  157. *
  158. *
  159. * @covers \Other\Class
  160. */
  161. class Test Extends TestCase
  162. {
  163. }
  164. }
  165. ',
  166. ],
  167. 'It always adds @small to the bottom of the doc block' => [
  168. '<?php
  169. /**
  170. * @coversNothing
  171. *
  172. *
  173. *
  174. *
  175. *
  176. *
  177. *
  178. *
  179. *
  180. *
  181. *
  182. *
  183. *
  184. *
  185. *
  186. * @small
  187. */
  188. class Test extends TestCase
  189. {
  190. }
  191. ',
  192. '<?php
  193. /**
  194. * @coversNothing
  195. *
  196. *
  197. *
  198. *
  199. *
  200. *
  201. *
  202. *
  203. *
  204. *
  205. *
  206. *
  207. *
  208. *
  209. */
  210. class Test extends TestCase
  211. {
  212. }
  213. ',
  214. ],
  215. 'It does not change a class with a single line @{size} doc block' => [
  216. '<?php
  217. /** @medium */
  218. class Test extends TestCase
  219. {
  220. }
  221. ',
  222. ],
  223. 'It adds an @small tag to a class that already has a one linedoc block' => [
  224. '<?php
  225. /**
  226. * @coversNothing
  227. *
  228. * @small
  229. */
  230. class Test extends TestCase
  231. {
  232. }
  233. ',
  234. '<?php
  235. /** @coversNothing */
  236. class Test extends TestCase
  237. {
  238. }
  239. ',
  240. ],
  241. 'By default it will not mark an abstract class as @small' => [
  242. '<?php
  243. abstract class Test
  244. {
  245. }
  246. ',
  247. ],
  248. 'It works correctly with multiple classes in one file, even when one of them is not allowed' => [
  249. '<?php
  250. /**
  251. * @small
  252. */
  253. class Test
  254. {
  255. }
  256. abstract class Test
  257. {
  258. }
  259. class FooBar
  260. {
  261. }
  262. /**
  263. * @small
  264. */
  265. class Test extends TestCase
  266. {
  267. }
  268. ',
  269. '<?php
  270. class Test
  271. {
  272. }
  273. abstract class Test
  274. {
  275. }
  276. class FooBar
  277. {
  278. }
  279. class Test extends TestCase
  280. {
  281. }
  282. ',
  283. ],
  284. ];
  285. }
  286. }