PhpUnitSizeClassFixerTest.php 4.3 KB

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