123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?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\FunctionNotation;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\FunctionNotation\DateTimeCreateFromFormatCallFixer
- *
- * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\FunctionNotation\DateTimeCreateFromFormatCallFixer>
- */
- final class DateTimeCreateFromFormatCallFixerTest extends AbstractFixerTestCase
- {
- /**
- * @dataProvider provideFixCases
- */
- public function testFix(string $expected, ?string $input = null): void
- {
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<int|string, array{0: string, 1?: string}>
- */
- public static function provideFixCases(): iterable
- {
- foreach ([\DateTime::class, \DateTimeImmutable::class] as $class) {
- $lowerCaseClass = strtolower($class);
- $upperCaseClass = strtoupper($class);
- yield [
- "<?php \\{$class}::createFromFormat('!Y-m-d', '2022-02-11');",
- "<?php \\{$class}::createFromFormat('Y-m-d', '2022-02-11');",
- ];
- yield [
- "<?php use {$class}; {$class}::createFromFormat('!Y-m-d', '2022-02-11');",
- "<?php use {$class}; {$class}::createFromFormat('Y-m-d', '2022-02-11');",
- ];
- yield [
- "<?php {$class}::createFromFormat('!Y-m-d', '2022-02-11');",
- "<?php {$class}::createFromFormat('Y-m-d', '2022-02-11');",
- ];
- yield [
- "<?php use \\Example\\{$class}; {$class}::createFromFormat('Y-m-d', '2022-02-11');",
- ];
- yield [
- "<?php use \\Example\\{$lowerCaseClass}; {$upperCaseClass}::createFromFormat('Y-m-d', '2022-02-11');",
- ];
- yield [
- "<?php \\{$class}::createFromFormat(\"!Y-m-d\", '2022-02-11');",
- "<?php \\{$class}::createFromFormat(\"Y-m-d\", '2022-02-11');",
- ];
- yield [
- "<?php \\{$class}::createFromFormat(\$foo, '2022-02-11');",
- ];
- yield [
- "<?php \\{$upperCaseClass}::createFromFormat( \"!Y-m-d\", '2022-02-11');",
- "<?php \\{$upperCaseClass}::createFromFormat( \"Y-m-d\", '2022-02-11');",
- ];
- yield [
- "<?php \\{$class}::createFromFormat(/* aaa */ '!Y-m-d', '2022-02-11');",
- "<?php \\{$class}::createFromFormat(/* aaa */ 'Y-m-d', '2022-02-11');",
- ];
- yield [
- "<?php /*1*//*2*/{$class}/*3*/::/*4*/createFromFormat/*5*/(/*6*/\"!Y-m-d\"/*7*/,/*8*/\"2022-02-11\"/*9*/)/*10*/ ?>",
- "<?php /*1*//*2*/{$class}/*3*/::/*4*/createFromFormat/*5*/(/*6*/\"Y-m-d\"/*7*/,/*8*/\"2022-02-11\"/*9*/)/*10*/ ?>",
- ];
- yield [
- "<?php \\{$class}::createFromFormat('Y-m-d');",
- ];
- yield [
- "<?php \\{$class}::createFromFormat(\$a, \$b);",
- ];
- yield [
- "<?php \\{$class}::createFromFormat('Y-m-d', \$b, \$c);",
- ];
- yield [
- "<?php A\\{$class}::createFromFormat('Y-m-d', '2022-02-11');",
- ];
- yield [
- "<?php A\\{$class}::createFromFormat('Y-m-d'.\"a\", '2022-02-11');",
- ];
- yield ["<?php \\{$class}::createFromFormat(123, '2022-02-11');"];
- yield [
- "<?php namespace {
- \\{$class}::createFromFormat('!Y-m-d', '2022-02-11');
- }
- namespace Bar {
- class {$class} extends Foo {}
- {$class}::createFromFormat('Y-m-d', '2022-02-11');
- }
- ",
- "<?php namespace {
- \\{$class}::createFromFormat('Y-m-d', '2022-02-11');
- }
- namespace Bar {
- class {$class} extends Foo {}
- {$class}::createFromFormat('Y-m-d', '2022-02-11');
- }
- ",
- ];
- yield $class.': binary string' => [
- "<?php \\{$class}::createFromFormat(b'!Y-m-d', '2022-02-11');",
- "<?php \\{$class}::createFromFormat(b'Y-m-d', '2022-02-11');",
- ];
- yield $class.': empty string' => [
- "<?php \\{$class}::createFromFormat('', '2022-02-11');",
- ];
- }
- }
- }
|