NativeFunctionTypeDeclarationCasingFixerTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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\Casing;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author SpacePossum
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Casing\NativeFunctionTypeDeclarationCasingFixer
  20. */
  21. final class NativeFunctionTypeDeclarationCasingFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, ?string $input = null): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. public function provideFixCases()
  31. {
  32. return [
  33. [
  34. '<?php
  35. class Foo
  36. {
  37. private function Bar(array $bar) {
  38. return false;
  39. }
  40. }
  41. ',
  42. '<?php
  43. class Foo
  44. {
  45. private function Bar(ARRAY $bar) {
  46. return false;
  47. }
  48. }
  49. ',
  50. ],
  51. [
  52. '<?php
  53. interface Foo
  54. {
  55. public function Bar(array $bar);
  56. }
  57. ',
  58. '<?php
  59. interface Foo
  60. {
  61. public function Bar(ArrAY $bar);
  62. }
  63. ',
  64. ],
  65. [
  66. '<?php
  67. function Foo(/**/array/**/$bar) {
  68. return false;
  69. }
  70. ',
  71. '<?php
  72. function Foo(/**/ARRAY/**/$bar) {
  73. return false;
  74. }
  75. ',
  76. ],
  77. [
  78. '<?php
  79. class Bar { function Foo(array $a, callable $b, self $c) {} }
  80. ',
  81. '<?php
  82. class Bar { function Foo(ARRAY $a, CALLABLE $b, Self $c) {} }
  83. ',
  84. ],
  85. [
  86. '<?php
  87. function Foo(INTEGER $a) {}
  88. ',
  89. ],
  90. ];
  91. }
  92. /**
  93. * @requires PHP <7.0
  94. *
  95. * @dataProvider provideFixPre70Cases
  96. */
  97. public function testFixPre70(string $expected): void
  98. {
  99. $this->doTest($expected);
  100. }
  101. public function provideFixPre70Cases()
  102. {
  103. return [
  104. ['<?php function Foo(BOOL $A, FLOAT $B, INT $C, STRING $D, ITERABLE $E, VOID $F, OBJECT $o) {}'],
  105. ['<?php class Foo { public function Foo(\INT $a) {}}'],
  106. ];
  107. }
  108. /**
  109. * @dataProvider provideFix70Cases
  110. * @requires PHP 7.0
  111. */
  112. public function testFix70(string $expected, ?string $input = null): void
  113. {
  114. $this->doTest($expected, $input);
  115. }
  116. public function provideFix70Cases()
  117. {
  118. return [
  119. [
  120. '<?php final class Foo1 { final public function Foo(bool $A, float $B, int $C, string $D): int {} }',
  121. '<?php final class Foo1 { final public function Foo(BOOL $A, FLOAT $B, INT $C, STRING $D): INT {} }',
  122. ],
  123. [
  124. '<?php function Foo(bool $A, float $B, int $C, string $D): int {}',
  125. '<?php function Foo(BOOL $A, FLOAT $B, INT $C, STRING $D): INT {}',
  126. ],
  127. [
  128. '<?php function Foo(): Foo\A { return new Foo(); }',
  129. ],
  130. ];
  131. }
  132. /**
  133. * @dataProvider provideFix71Cases
  134. * @requires PHP 7.1
  135. */
  136. public function testFix71(string $expected, string $input): void
  137. {
  138. $this->doTest($expected, $input);
  139. }
  140. public function provideFix71Cases()
  141. {
  142. return [
  143. [
  144. '<?php trait XYZ { function Foo(iterable $A): void {} }',
  145. '<?php trait XYZ { function Foo(ITERABLE $A): VOID {} }',
  146. ],
  147. [
  148. '<?php function Foo(iterable $A): void {}',
  149. '<?php function Foo(ITERABLE $A): VOID {}',
  150. ],
  151. [
  152. '<?php function Foo(?int $A): void {}',
  153. '<?php function Foo(?INT $A): VOID {}',
  154. ],
  155. [
  156. '<?php function Foo(string $A): ?/* */int {}',
  157. '<?php function Foo(STRING $A): ?/* */INT {}',
  158. ],
  159. ];
  160. }
  161. /**
  162. * @dataProvider provideFix72Cases
  163. * @requires PHP 7.2
  164. */
  165. public function testFix72(string $expected, string $input): void
  166. {
  167. $this->doTest($expected, $input);
  168. }
  169. public function provideFix72Cases()
  170. {
  171. return [
  172. [
  173. '<?php function Foo(object $A): void {}',
  174. '<?php function Foo(OBJECT $A): VOID {}',
  175. ],
  176. ];
  177. }
  178. /**
  179. * @dataProvider provideFix80Cases
  180. * @requires PHP 8.0
  181. */
  182. public function testFix80(string $expected, string $input): void
  183. {
  184. $this->doTest($expected, $input);
  185. }
  186. public function provideFix80Cases()
  187. {
  188. yield [
  189. '<?php class T { public function Foo(object $A): static {}}',
  190. '<?php class T { public function Foo(object $A): StatiC {}}',
  191. ];
  192. yield [
  193. '<?php class T { public function Foo(object $A): ?static {}}',
  194. '<?php class T { public function Foo(object $A): ?StatiC {}}',
  195. ];
  196. yield [
  197. '<?php class T { public function Foo(mixed $A): mixed {}}',
  198. '<?php class T { public function Foo(Mixed $A): MIXED {}}',
  199. ];
  200. }
  201. }