PhpUnitInternalClassFixerTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 Gert de Pagter <BackEndTea@gmail.com>
  17. *
  18. * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitInternalClassFixer
  19. */
  20. final class PhpUnitInternalClassFixerTest extends AbstractFixerTestCase
  21. {
  22. /**
  23. * @dataProvider provideFixCases
  24. *
  25. * @param string $expected
  26. * @param null|string $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 internal' => [
  45. '<?php
  46. /**
  47. * @internal
  48. */
  49. class Test extends TestCase
  50. {
  51. }
  52. ',
  53. '<?php
  54. class Test extends TestCase
  55. {
  56. }
  57. ',
  58. ],
  59. 'It adds an internal tag to a class that already has a doc block' => [
  60. '<?php
  61. /**
  62. * @coversNothing
  63. *
  64. * @internal
  65. */
  66. class Test extends TestCase
  67. {
  68. }
  69. ',
  70. '<?php
  71. /**
  72. * @coversNothing
  73. */
  74. class Test extends TestCase
  75. {
  76. }
  77. ',
  78. ],
  79. 'It does not change a class that is already internal' => [
  80. '<?php
  81. /**
  82. * @internal
  83. */
  84. class Test extends TestCase
  85. {
  86. }
  87. ',
  88. ],
  89. 'It does not change a class that is already internal and has other annotations' => [
  90. '<?php
  91. /**
  92. * @author me
  93. * @coversNothing
  94. * @internal
  95. * @group large
  96. */
  97. class Test extends TestCase
  98. {
  99. }
  100. ',
  101. ],
  102. 'It works on other indentation levels' => [
  103. '<?php
  104. if (class_exists("Foo\Bar")) {
  105. /**
  106. * @internal
  107. */
  108. class Test Extends TestCase
  109. {
  110. }
  111. }
  112. ',
  113. '<?php
  114. if (class_exists("Foo\Bar")) {
  115. class Test Extends TestCase
  116. {
  117. }
  118. }
  119. ',
  120. ],
  121. 'It works on other indentation levels when the class has other annotations' => [
  122. '<?php
  123. if (class_exists("Foo\Bar")) {
  124. /**
  125. * @author me again
  126. *
  127. *
  128. * @covers \Other\Class
  129. *
  130. * @internal
  131. */
  132. class Test Extends TestCase
  133. {
  134. }
  135. }
  136. ',
  137. '<?php
  138. if (class_exists("Foo\Bar")) {
  139. /**
  140. * @author me again
  141. *
  142. *
  143. * @covers \Other\Class
  144. */
  145. class Test Extends TestCase
  146. {
  147. }
  148. }
  149. ',
  150. ],
  151. 'It works for tab ident' => [
  152. '<?php
  153. if (class_exists("Foo\Bar")) {
  154. /**
  155. * @author me again
  156. *
  157. *
  158. * @covers \Other\Class
  159. *
  160. * @internal
  161. */
  162. class Test Extends TestCase
  163. {
  164. }
  165. }
  166. ',
  167. '<?php
  168. if (class_exists("Foo\Bar")) {
  169. /**
  170. * @author me again
  171. *
  172. *
  173. * @covers \Other\Class
  174. */
  175. class Test Extends TestCase
  176. {
  177. }
  178. }
  179. ',
  180. ],
  181. 'It always adds @internal to the bottom of the doc block' => [
  182. '<?php
  183. /**
  184. * @coversNothing
  185. *
  186. *
  187. *
  188. *
  189. *
  190. *
  191. *
  192. *
  193. *
  194. *
  195. *
  196. *
  197. *
  198. *
  199. *
  200. * @internal
  201. */
  202. class Test extends TestCase
  203. {
  204. }
  205. ',
  206. '<?php
  207. /**
  208. * @coversNothing
  209. *
  210. *
  211. *
  212. *
  213. *
  214. *
  215. *
  216. *
  217. *
  218. *
  219. *
  220. *
  221. *
  222. *
  223. */
  224. class Test extends TestCase
  225. {
  226. }
  227. ',
  228. ],
  229. 'It does not change a class with a single line internal doc block' => [
  230. '<?php
  231. /** @internal */
  232. class Test extends TestCase
  233. {
  234. }
  235. ',
  236. ],
  237. 'It adds an internal tag to a class that already has a one linedoc block' => [
  238. '<?php
  239. /**
  240. * @coversNothing
  241. *
  242. * @internal
  243. */
  244. class Test extends TestCase
  245. {
  246. }
  247. ',
  248. '<?php
  249. /** @coversNothing */
  250. class Test extends TestCase
  251. {
  252. }
  253. ',
  254. ],
  255. 'By default it will not mark an abstract class as internal' => [
  256. '<?php
  257. abstract class Test
  258. {
  259. }
  260. ',
  261. ],
  262. 'If abstract is added as an option, abstract classes will be marked internal' => [
  263. '<?php
  264. /**
  265. * @internal
  266. */
  267. abstract class Test
  268. {
  269. }
  270. ',
  271. '<?php
  272. abstract class Test
  273. {
  274. }
  275. ',
  276. [
  277. 'types' => ['abstract'],
  278. ],
  279. ],
  280. 'If final is not added as an option, final classes will not be marked internal' => [
  281. '<?php
  282. final class Test
  283. {
  284. }
  285. ',
  286. null,
  287. [
  288. 'types' => ['abstract'],
  289. ],
  290. ],
  291. 'If normal is not added as an option, normal classes will not be marked internal' => [
  292. '<?php
  293. class Test
  294. {
  295. }
  296. ',
  297. null,
  298. [
  299. 'types' => ['abstract'],
  300. ],
  301. ],
  302. 'It works correctly with multiple classes in one file, even when one of them is not allowed' => [
  303. '<?php
  304. /**
  305. * @internal
  306. */
  307. class Test
  308. {
  309. }
  310. abstract class Test
  311. {
  312. }
  313. class FooBar
  314. {
  315. }
  316. /**
  317. * @internal
  318. */
  319. class Test extends TestCase
  320. {
  321. }
  322. ',
  323. '<?php
  324. class Test
  325. {
  326. }
  327. abstract class Test
  328. {
  329. }
  330. class FooBar
  331. {
  332. }
  333. class Test extends TestCase
  334. {
  335. }
  336. ',
  337. ],
  338. ];
  339. }
  340. }