PhpdocVarWithoutNameFixerTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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\Phpdoc;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. /**
  14. * @author Graham Campbell <graham@alt-three.com>
  15. *
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocVarWithoutNameFixer
  19. */
  20. final class PhpdocVarWithoutNameFixerTest extends AbstractFixerTestCase
  21. {
  22. /**
  23. * @dataProvider provideFixVarCases
  24. *
  25. * @param string $expected
  26. * @param string|null $input
  27. */
  28. public function testFixVar($expected, $input = null)
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. /**
  33. * @dataProvider provideFixVarCases
  34. *
  35. * @param string $expected
  36. * @param string|null $input
  37. */
  38. public function testFixType($expected, $input = null)
  39. {
  40. $expected = str_replace('@var', '@type', $expected);
  41. if (null !== $input) {
  42. $input = str_replace('@var', '@type', $input);
  43. }
  44. $this->doTest($expected, $input);
  45. }
  46. public function provideFixVarCases()
  47. {
  48. return array(
  49. 'testFixVar' => array(
  50. <<<'EOF'
  51. <?php
  52. /**
  53. * @var string Hello!
  54. */
  55. EOF
  56. ,
  57. <<<'EOF'
  58. <?php
  59. /**
  60. * @var string $foo Hello!
  61. */
  62. EOF
  63. ,
  64. ),
  65. 'testFixType' => array(
  66. <<<'EOF'
  67. <?php
  68. /**
  69. * @var int|null
  70. */
  71. EOF
  72. ,
  73. <<<'EOF'
  74. <?php
  75. /**
  76. * @var int|null $bar
  77. */
  78. EOF
  79. ,
  80. ),
  81. 'testDoNothing' => array(
  82. <<<'EOF'
  83. <?php
  84. /**
  85. * @var Foo\Bar This is a variable.
  86. */
  87. EOF
  88. ),
  89. 'testFixVarWithOtherAnnotation' => array(
  90. <<<'EOF'
  91. <?php
  92. /**
  93. * @var string Hello!
  94. *
  95. * @deprecated
  96. */
  97. EOF
  98. ,
  99. <<<'EOF'
  100. <?php
  101. /**
  102. * @var string $foo Hello!
  103. *
  104. * @deprecated
  105. */
  106. EOF
  107. ,
  108. ),
  109. 'testFixVarWithNestedKeys' => array(
  110. <<<'EOF'
  111. <?php
  112. /**
  113. * @var array {
  114. * @var bool $required Whether this element is required
  115. * @var string $label The display name for this element
  116. * }
  117. */
  118. EOF
  119. ,
  120. <<<'EOF'
  121. <?php
  122. /**
  123. * @var array $options {
  124. * @var bool $required Whether this element is required
  125. * @var string $label The display name for this element
  126. * }
  127. */
  128. EOF
  129. ),
  130. 'testSingleLine' => array(
  131. <<<'EOF'
  132. <?php
  133. /** @var Foo\Bar $bar */
  134. $bar;
  135. EOF
  136. ,
  137. ),
  138. 'testEmpty' => array(
  139. <<<'EOF'
  140. <?php
  141. /**
  142. *
  143. */
  144. EOF
  145. ,
  146. ),
  147. 'testInlineDoc' => array(
  148. <<<'EOF'
  149. <?php
  150. /**
  151. * Initializes this class with the given options.
  152. *
  153. * @param array $options {
  154. * @var bool $required Whether this element is required
  155. * @var string $label The display name for this element
  156. * }
  157. */
  158. EOF
  159. ,
  160. ),
  161. 'testInlineDocAgain' => array(
  162. <<<'EOF'
  163. <?php
  164. /**
  165. * @param int[] $stuff {
  166. * @var int $foo
  167. * }
  168. *
  169. * @return void
  170. */
  171. EOF
  172. ,
  173. ),
  174. );
  175. }
  176. }