PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Symfony/CS/Tests/Fixer/Symfony/PhpdocToCommentFixerTest.php

http://github.com/fabpot/PHP-CS-Fixer
PHP | 533 lines | 479 code | 35 blank | 19 comment | 0 complexity | 0f9bb333f3449e2daa3caba5d439b8d9 MD5 | raw file
  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 Symfony\CS\Tests\Fixer\Symfony;
  12. use Symfony\CS\Tests\Fixer\AbstractFixerTestBase;
  13. /**
  14. * @author Ceeram <ceeram@cakephp.org>
  15. */
  16. class PhpdocToCommentFixerTest extends AbstractFixerTestBase
  17. {
  18. /**
  19. * @dataProvider provideDocblocks
  20. */
  21. public function testFix($expected, $input = null)
  22. {
  23. $this->makeTest($expected, $input);
  24. }
  25. /**
  26. * @requires PHP 5.4
  27. * @dataProvider provideTraits
  28. */
  29. public function testFixTraits($expected, $input = null)
  30. {
  31. $this->makeTest($expected, $input);
  32. }
  33. public function provideDocblocks()
  34. {
  35. $cases = array();
  36. $cases[] = array(
  37. '<?php
  38. /**
  39. * Do not convert this
  40. */
  41. namespace Docs;
  42. /**
  43. * Do not convert this
  44. */
  45. class DocBlocks
  46. {
  47. /**
  48. * Do not convert this
  49. */
  50. const STRUCTURAL = true;
  51. /**
  52. * Do not convert this
  53. */
  54. protected $indent = false;
  55. /**
  56. * Do not convert this
  57. */
  58. var $oldPublicStyle;
  59. /**
  60. * Do not convert this
  61. */
  62. public function test() {}
  63. /**
  64. * Do not convert this
  65. */
  66. private function testPrivate() {}
  67. /**
  68. * Do not convert this
  69. */
  70. function testNoVisibility() {}
  71. }',
  72. );
  73. $cases[] = array(
  74. '<?php namespace Docs;
  75. /**
  76. * Do not convert this
  77. */
  78. /**
  79. * Do not convert this
  80. */
  81. class DocBlocks{}
  82. ',
  83. );
  84. $cases[] = array(
  85. '<?php
  86. /**
  87. * Do not convert this
  88. */
  89. namespace Foo;
  90. ',
  91. );
  92. $cases[] = array(
  93. '<?php
  94. $first = true;// needed because by default first docblock is never fixed.
  95. /**
  96. * Do not convert this
  97. */
  98. abstract class DocBlocks
  99. {
  100. /**
  101. * Do not convert this
  102. */
  103. abstract public function test();
  104. }',
  105. );
  106. $cases[] = array(
  107. '<?php
  108. $first = true;// needed because by default first docblock is never fixed.
  109. /**
  110. * Do not convert this
  111. */
  112. interface DocBlocks
  113. {
  114. public function test();
  115. }',
  116. );
  117. $cases[] = array(
  118. '<?php
  119. namespace NS;
  120. /**
  121. * Do not
  122. */
  123. final class Foo
  124. {
  125. }',
  126. );
  127. $cases[] = array(
  128. '<?php
  129. $first = true;// needed because by default first docblock is never fixed.
  130. /**
  131. * Do not convert this
  132. */
  133. require "require.php";
  134. /**
  135. * Do not convert this
  136. */
  137. require_once "require_once.php";
  138. /**
  139. * Do not convert this
  140. */
  141. include "include.php";
  142. /**
  143. * Do not convert this
  144. */
  145. include_once "include_once.php";
  146. ',
  147. );
  148. $cases[] = array(
  149. '<?php
  150. $first = true;// needed because by default first docblock is never fixed.
  151. /**
  152. * Do not convert this
  153. *
  154. * @var int
  155. */
  156. $a = require "require.php";
  157. /**
  158. * Do not convert this
  159. *
  160. * @var int
  161. */
  162. $b = require_once "require_once.php";
  163. /**
  164. * Do not convert this
  165. *
  166. * @var int
  167. */
  168. $c = include "include.php";
  169. /**
  170. * Do not convert this
  171. *
  172. * @var int
  173. */
  174. $d = include_once "include_once.php";
  175. /**
  176. * @var Composer\Autoload\ClassLoader $loader
  177. */
  178. $loader = require_once __DIR__."/vendor/autoload.php";
  179. ',
  180. );
  181. $cases[] = array(
  182. '<?php
  183. $first = true;// needed because by default first docblock is never fixed.
  184. /**
  185. * @var ClassLoader $loader
  186. */
  187. $loader = require_once __DIR__."/../app/autoload.php";
  188. ',
  189. );
  190. $cases[] = array(
  191. '<?php
  192. $first = true;// needed because by default first docblock is never fixed.
  193. /**
  194. * Do not convert this
  195. *
  196. * @var Foo
  197. */
  198. $foo = createFoo();
  199. ',
  200. );
  201. $cases[] = array(
  202. '<?php
  203. $first = true;// needed because by default first docblock is never fixed.
  204. /**
  205. * Do not convert this
  206. *
  207. * @var bool $local
  208. */
  209. $local = true;
  210. ',
  211. );
  212. $cases[] = array(
  213. '<?php
  214. $first = true;// needed because by default first docblock is never fixed.
  215. /**
  216. * Comment
  217. */
  218. $local = true;
  219. ',
  220. );
  221. $cases[] = array(
  222. '<?php
  223. $first = true;// needed because by default first docblock is never fixed.
  224. /** @var \Sqlite3 $sqlite */
  225. foreach($connections as $sqlite) {
  226. $sqlite->open($path);
  227. }',
  228. );
  229. $cases[] = array(
  230. '<?php
  231. $first = true;// needed because by default first docblock is never fixed.
  232. /** @var \Sqlite3 $sqlite */
  233. foreach($connections as $key => $sqlite) {
  234. $sqlite->open($path);
  235. }',
  236. );
  237. $cases[] = array(
  238. '<?php
  239. $first = true;// needed because by default first docblock is never fixed.
  240. /** @var int $key */
  241. foreach($connections as $key => $sqlite) {
  242. $sqlite->open($path);
  243. }',
  244. );
  245. $cases[] = array(
  246. '<?php
  247. $first = true;// needed because by default first docblock is never fixed.
  248. /* This should not be a docblock */
  249. foreach($connections as $key => $sqlite) {
  250. $sqlite->open($path);
  251. }',
  252. '<?php
  253. $first = true;// needed because by default first docblock is never fixed.
  254. /** This should not be a docblock */
  255. foreach($connections as $key => $sqlite) {
  256. $sqlite->open($path);
  257. }',
  258. );
  259. $cases[] = array(
  260. '<?php
  261. $first = true;// needed because by default first docblock is never fixed.
  262. /* there should be no docblock here */
  263. $sqlite1->open($path);
  264. ',
  265. '<?php
  266. $first = true;// needed because by default first docblock is never fixed.
  267. /** there should be no docblock here */
  268. $sqlite1->open($path);
  269. ',
  270. );
  271. $cases[] = array(
  272. '<?php
  273. $first = true;// needed because by default first docblock is never fixed.
  274. /* there should be no docblock here */
  275. $i++;
  276. ',
  277. '<?php
  278. $first = true;// needed because by default first docblock is never fixed.
  279. /** there should be no docblock here */
  280. $i++;
  281. ',
  282. );
  283. $cases[] = array(
  284. '<?php
  285. $first = true;// needed because by default first docblock is never fixed.
  286. /** @var int $index */
  287. $index = $a[\'number\'];
  288. ',
  289. );
  290. $cases[] = array(
  291. '<?php
  292. $first = true;// needed because by default first docblock is never fixed.
  293. /** @var string $two */
  294. list($one, $two) = explode("," , $csvLines);
  295. ',
  296. );
  297. $cases[] = array(
  298. '<?php
  299. $first = true;// needed because by default first docblock is never fixed.
  300. /* This should be a comment */
  301. list($one, $two) = explode("," , $csvLines);
  302. ',
  303. '<?php
  304. $first = true;// needed because by default first docblock is never fixed.
  305. /** This should be a comment */
  306. list($one, $two) = explode("," , $csvLines);
  307. ',
  308. );
  309. $cases[] = array(
  310. '<?php
  311. $first = true;// needed because by default first docblock is never fixed.
  312. /** @var int $index */
  313. foreach ($foo->getPairs($c->bar(), $bar) as $index => list($a, $b)) {
  314. // Do something with $index, $a and $b
  315. }
  316. /** @var \Closure $value */
  317. if (!$value = $this->getValue()) {
  318. return false;
  319. }
  320. /** @var string $name */
  321. switch ($name = $this->getName()) {
  322. case "John":
  323. return false;
  324. case "Jane":
  325. return true;
  326. }
  327. /** @var string $content */
  328. while ($content = $this->getContent()) {
  329. $name .= $content;
  330. }
  331. /** @var int $size */
  332. for($i = 0, $size = count($people); $i < $size; ++$i) {
  333. $people[$i][\'salt\'] = mt_rand(000000, 999999);
  334. }',
  335. );
  336. $cases[] = array(
  337. '<?php
  338. $first = true;// needed because by default first docblock is never fixed.
  339. /* @var int $wrong */
  340. foreach ($foo->getPairs($c->bar(), $bar) as $index => list($a, $b)) {
  341. // Do something with $index, $a and $b
  342. }
  343. /* @var \Closure $notValue */
  344. if (!$value = $this->getValue()) {
  345. return false;
  346. }
  347. /* @var string $notName */
  348. switch ($name = $this->getName()) {
  349. case "John":
  350. return false;
  351. case "Jane":
  352. return true;
  353. }
  354. /* @var string $notContent */
  355. while ($content = $this->getContent()) {
  356. $name .= $content;
  357. }
  358. /* @var int $notSize */
  359. for($i = 0, $size = count($people); $i < $size; ++$i) {
  360. $people[$i][\'salt\'] = mt_rand(000000, 999999);
  361. }',
  362. '<?php
  363. $first = true;// needed because by default first docblock is never fixed.
  364. /** @var int $wrong */
  365. foreach ($foo->getPairs($c->bar(), $bar) as $index => list($a, $b)) {
  366. // Do something with $index, $a and $b
  367. }
  368. /** @var \Closure $notValue */
  369. if (!$value = $this->getValue()) {
  370. return false;
  371. }
  372. /** @var string $notName */
  373. switch ($name = $this->getName()) {
  374. case "John":
  375. return false;
  376. case "Jane":
  377. return true;
  378. }
  379. /** @var string $notContent */
  380. while ($content = $this->getContent()) {
  381. $name .= $content;
  382. }
  383. /** @var int $notSize */
  384. for($i = 0, $size = count($people); $i < $size; ++$i) {
  385. $people[$i][\'salt\'] = mt_rand(000000, 999999);
  386. }',
  387. );
  388. $cases[] = array(
  389. '<?php
  390. /* This should be a comment */
  391. ',
  392. '<?php
  393. /** This should be a comment */
  394. ',
  395. );
  396. $cases[] = array(
  397. '<?php
  398. /**
  399. * This is a page level docblock should stay untouched
  400. */
  401. echo "Some string";
  402. ',
  403. );
  404. $cases[] = array(
  405. '<?php
  406. $first = true;// needed because by default first docblock is never fixed.
  407. /** @var \NumberFormatter $formatter */
  408. static $formatter;
  409. ',
  410. );
  411. $cases[] = array(
  412. '<?php
  413. $first = true;// needed because by default first docblock is never fixed.
  414. function getNumberFormatter()
  415. {
  416. /** @var \NumberFormatter $formatter */
  417. static $formatter;
  418. }
  419. ',
  420. );
  421. return $cases;
  422. }
  423. public function provideTraits()
  424. {
  425. return array(
  426. array(
  427. '<?php
  428. $first = true;// needed because by default first docblock is never fixed.
  429. /**
  430. * Do not convert this
  431. */
  432. trait DocBlocks
  433. {
  434. public function test() {}
  435. }',
  436. ),
  437. );
  438. }
  439. }