123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <?php
- declare(strict_types=1);
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace PhpCsFixer\Tests\Fixer\Casing;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\Casing\NativeFunctionTypeDeclarationCasingFixer
- */
- final class NativeFunctionTypeDeclarationCasingFixerTest extends AbstractFixerTestCase
- {
- /**
- * @dataProvider provideFixCases
- */
- public function testFix(string $expected, ?string $input = null): void
- {
- $this->doTest($expected, $input);
- }
- public static function provideFixCases(): array
- {
- return [
- [
- '<?php
- class Foo
- {
- private function Bar(array $bar) {
- return false;
- }
- }
- ',
- '<?php
- class Foo
- {
- private function Bar(ARRAY $bar) {
- return false;
- }
- }
- ',
- ],
- [
- '<?php
- interface Foo
- {
- public function Bar(array $bar);
- }
- ',
- '<?php
- interface Foo
- {
- public function Bar(ArrAY $bar);
- }
- ',
- ],
- [
- '<?php
- function Foo(/**/array/**/$bar) {
- return false;
- }
- ',
- '<?php
- function Foo(/**/ARRAY/**/$bar) {
- return false;
- }
- ',
- ],
- [
- '<?php
- class Bar { function Foo(array $a, callable $b, self $c) {} }
- ',
- '<?php
- class Bar { function Foo(ARRAY $a, CALLABLE $b, Self $c) {} }
- ',
- ],
- [
- '<?php
- function Foo(INTEGER $a) {}
- ',
- ],
- [
- '<?php function Foo(
- String\A $x,
- B\String\C $y
- ) {}',
- ],
- [
- '<?php final class Foo1 { final public function Foo(bool $A, float $B, int $C, string $D): int {} }',
- '<?php final class Foo1 { final public function Foo(BOOL $A, FLOAT $B, INT $C, STRING $D): INT {} }',
- ],
- [
- '<?php function Foo(bool $A, float $B, int $C, string $D): int {}',
- '<?php function Foo(BOOL $A, FLOAT $B, INT $C, STRING $D): INT {}',
- ],
- [
- '<?php function Foo(): Foo\A { return new Foo(); }',
- ],
- [
- '<?php trait XYZ { function Foo(iterable $A): void {} }',
- '<?php trait XYZ { function Foo(ITERABLE $A): VOID {} }',
- ],
- [
- '<?php function Foo(iterable $A): void {}',
- '<?php function Foo(ITERABLE $A): VOID {}',
- ],
- [
- '<?php function Foo(?int $A): void {}',
- '<?php function Foo(?INT $A): VOID {}',
- ],
- [
- '<?php function Foo(string $A): ?/* */int {}',
- '<?php function Foo(STRING $A): ?/* */INT {}',
- ],
- [
- '<?php function Foo(object $A): void {}',
- '<?php function Foo(OBJECT $A): VOID {}',
- ],
- [
- '<?php return function (callable $c) {};',
- '<?php return function (CALLABLE $c) {};',
- ],
- ];
- }
- /**
- * @dataProvider provideFix80Cases
- *
- * @requires PHP 8.0
- */
- public function testFix80(string $expected, string $input): void
- {
- $this->doTest($expected, $input);
- }
- public static function provideFix80Cases(): iterable
- {
- yield [
- '<?php class T { public function Foo(object $A): static {}}',
- '<?php class T { public function Foo(object $A): StatiC {}}',
- ];
- yield [
- '<?php class T { public function Foo(object $A): ?static {}}',
- '<?php class T { public function Foo(object $A): ?StatiC {}}',
- ];
- yield [
- '<?php class T { public function Foo(mixed $A): mixed {}}',
- '<?php class T { public function Foo(Mixed $A): MIXED {}}',
- ];
- yield [
- '<?php function foo(int|bool $x) {}',
- '<?php function foo(INT|BOOL $x) {}',
- ];
- yield [
- '<?php function foo(int | bool $x) {}',
- '<?php function foo(INT | BOOL $x) {}',
- ];
- yield [
- '<?php function foo(): int|bool {}',
- '<?php function foo(): INT|BOOL {}',
- ];
- yield 'return type string|false' => [
- '<?php function foo(): string|false {}',
- '<?php function foo(): string|FALSE {}',
- ];
- yield 'return type string|null' => [
- '<?php function foo(): string|null {}',
- '<?php function foo(): string|NULL {}',
- ];
- }
- /**
- * @dataProvider provideFix81Cases
- *
- * @requires PHP 8.1
- */
- public function testFix81(string $expected, string $input): void
- {
- $this->doTest($expected, $input);
- }
- public static function provideFix81Cases(): iterable
- {
- yield 'return type `never`' => [
- '<?php class T { public function Foo(object $A): never {die;}}',
- '<?php class T { public function Foo(object $A): NEVER {die;}}',
- ];
- }
- /**
- * @dataProvider provideFix82Cases
- *
- * @requires PHP 8.2
- */
- public function testFix82(string $expected, string $input): void
- {
- $this->doTest($expected, $input);
- }
- public static function provideFix82Cases(): iterable
- {
- foreach (['true', 'false', 'null'] as $type) {
- yield sprintf('standalone type `%s` in class method', $type) => [
- sprintf('<?php class T { public function Foo(%s $A): %1$s {return $A;}}', $type),
- sprintf('<?php class T { public function Foo(%s $A): %1$s {return $A;}}', strtoupper($type)),
- ];
- yield sprintf('standalone type `%s` in function', $type) => [
- sprintf('<?php function Foo(%s $A): %1$s {return $A;}', $type),
- sprintf('<?php function Foo(%s $A): %1$s {return $A;}', strtoupper($type)),
- ];
- yield sprintf('standalone type `%s` in closure', $type) => [
- sprintf('<?php array_filter([], function (%s $A): %1$s {return $A;});', $type),
- sprintf('<?php array_filter([], function (%s $A): %1$s {return $A;});', strtoupper($type)),
- ];
- }
- }
- }
|