123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- <?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\ClassReferenceNameCasingFixer
- *
- * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Casing\ClassReferenceNameCasingFixer>
- */
- final class ClassReferenceNameCasingFixerTest extends AbstractFixerTestCase
- {
- /**
- * @dataProvider provideFixCases
- */
- public function testFix(string $expected, ?string $input = null): void
- {
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<array{0: string, 1?: string}>
- */
- public static function provideFixCases(): iterable
- {
- yield [
- '<?php
- $a = new Exception;
- $b = new \Exception;
- $c = new Exception();
- $d = new \Exception();
- $e = "a".Exception::class;
- $f = "a".\Exception::class;
- $g .= "exception";
- echo \Exception::class;
- print(Exception::class);
- // $a = new exception();
- /** $a = new exception(); */
- ',
- '<?php
- $a = new exception;
- $b = new \exception;
- $c = new exception();
- $d = new \exception();
- $e = "a".exception::class;
- $f = "a".\exception::class;
- $g .= "exception";
- echo \exception::class;
- print(exception::class);
- // $a = new exception();
- /** $a = new exception(); */
- ',
- ];
- yield [
- '<?php namespace Foo {
- $a = new exception;
- $b = new \Exception;
- }',
- '<?php namespace Foo {
- $a = new exception;
- $b = new \exception;
- }',
- ];
- yield [
- '<?php namespace Foo;
- $a = new exception;
- $b = new \Exception;
- ',
- '<?php namespace Foo;
- $a = new exception;
- $b = new \EXCEPTION;
- ',
- ];
- yield [
- '<?php
- $a = exception();
- $b = new A\exception;
- $c = new A\B\C\exception;
- $a1 = \exception();
- $b1 = new \A\exception;
- $c1 = new \A\B\C\exception;
- ',
- ];
- yield [
- '<?php class Foo extends Exception {};',
- '<?php class Foo extends exception {};',
- ];
- yield [
- '<?php class exception {}; new foO();',
- ];
- yield [
- '<?php interface exception {};',
- ];
- yield [
- '<?php trait exception {};',
- ];
- yield [
- '<?php function exception() {};',
- ];
- yield [
- '<?php const exception = "abc";',
- ];
- yield [
- '<?php $a = Foo::exception;',
- ];
- yield [
- '<?php $a = $foo->exception;',
- ];
- yield [
- '<?php use Foo as exception;',
- ];
- yield [
- '<?php class Foo { use exception; }',
- ];
- yield [
- '<?php $foo = ["const" => exception];',
- ];
- yield [
- '<?php
- namespace {
- $a = new Exception;
- $b = new \Exception;
- }
- namespace Bar {
- $a = new exception;
- $b = new \Exception;
- }
- namespace Foo {
- $a = new exception;
- $b = new \Exception;
- $c = new foO();
- }',
- '<?php
- namespace {
- $a = new exception;
- $b = new \exception;
- }
- namespace Bar {
- $a = new exception;
- $b = new \exception;
- }
- namespace Foo {
- $a = new exception;
- $b = new \exception;
- $c = new foO();
- }',
- ];
- yield [
- '<?php use Exception as baR;',
- '<?php use exception as baR;',
- ];
- yield [
- '<?php try { foo(); } catch(\LogicException $e) {}',
- '<?php try { foo(); } catch(\logicexception $e) {}',
- ];
- yield [
- '<?php try { foo(); } catch(LogicException $e) {}',
- '<?php try { foo(); } catch(logicexception $e) {}',
- ];
- yield [
- '<?php
- Closure::bind(fn () => null, null, new class {});
- \Closure::bind(fn () => null, null, new class {});
- Foo\Bar::bind(fn () => null, null, new class {});
- \A\B\Bar::bind(fn () => null, null, new class {});
- ',
- '<?php
- CLOSURE::bind(fn () => null, null, new class {});
- \CLOSURE::bind(fn () => null, null, new class {});
- Foo\Bar::bind(fn () => null, null, new class {});
- \A\B\Bar::bind(fn () => null, null, new class {});
- ',
- ];
- yield [
- "<?php
- declare(strict_types=1);
- use Sonata\\Exporter\\Writer\\EXCEPTION;
- \$services->set('sonata.exporter.writer.xml', EXCEPTION::class);
- ",
- ];
- yield [
- '<?php
- const error = 1;
- foo(error);
- $b2 = $a[error];
- $b21 = [1,error];
- $b22 = [error,2];
- $b23 = [1,error,2];
- $b24 = [1,error,2,];
- $b3 = [error];
- $b4 = $a->{error};
- ',
- ];
- yield [
- '<?php
- foo(\error);
- $b2 = $a[\error];
- $b21 = [1,\error];
- $b22 = [\error,2];
- $b23 = [1,\error,2];
- $b24 = [1,\error,2,];
- $b3 = [\error];
- $b4 = $a->{\error};
- ',
- ];
- yield ['<?php echo error ?><?php echo error;'];
- }
- /**
- * @dataProvider provideFix80Cases
- *
- * @requires PHP 8.0
- */
- public function testFix80(string $expected, ?string $input = null): void
- {
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<array{0: string, 1?: string}>
- */
- public static function provideFix80Cases(): iterable
- {
- yield [
- '<?php if ($var?->exception instanceof Exception) {};',
- ];
- }
- /**
- * @dataProvider provideFix81Cases
- *
- * @requires PHP 8.1
- */
- public function testFix81(string $expected, ?string $input = null): void
- {
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<int|string, array{0: string, 1?: string}>
- */
- public static function provideFix81Cases(): iterable
- {
- yield [
- '<?php enum exception {}',
- ];
- yield [
- '<?php enum Foo {
- case exception;
- }',
- ];
- yield 'multiple type catch with variable' => [
- '<?php try { foo(); } catch(\InvalidArgumentException|\LogicException $e) {}',
- '<?php try { foo(); } catch(\INVALIDARGUMENTEXCEPTION|\logicexception $e) {}',
- ];
- yield 'multiple type catch without variable 3' => [
- '<?php try { foo(); } catch(\InvalidArgumentException|\LogicException) {}',
- '<?php try { foo(); } catch(\INVALIDARGUMENTEXCEPTION|\logicexception) {}',
- ];
- }
- }
|