* Dariusz Rumiński * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace PhpCsFixer\Tests\Fixer\Basic; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; use Prophecy\Prophet; /** * @author Graham Campbell * @author Kuba Werłos * * @internal * * @covers \PhpCsFixer\Fixer\Basic\PsrAutoloadingFixer */ final class PsrAutoloadingFixerTest extends AbstractFixerTestCase { /** * This is new test method, to replace old one some day. * * @dataProvider provideFixNewCases */ public function testFixNew(string $expected, ?string $input = null, ?string $dir = null): void { if (null !== $dir) { $this->fixer->configure(['dir' => $dir]); } $this->doTest($expected, $input, self::getTestFile(__FILE__)); } public static function provideFixNewCases(): iterable { foreach (['class', 'interface', 'trait'] as $element) { yield sprintf('%s with originally short name', $element) => [ sprintf(' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ 'fixer->configure(['dir' => $dir]); } $this->doTest($expected, $input, $file); } public static function provideFixCases(): iterable { $prophet = new Prophet(); $fileProphecy = $prophet->prophesize(\SplFileInfo::class); $fileProphecy->willBeConstructedWith(['']); $fileProphecy->getBasename('.php')->willReturn('Bar'); $fileProphecy->getExtension()->willReturn('php'); $fileProphecy->getRealPath()->willReturn(__DIR__.\DIRECTORY_SEPARATOR.'Psr'.\DIRECTORY_SEPARATOR.'Foo'.\DIRECTORY_SEPARATOR.'Bar.php'); $file = $fileProphecy->reveal(); yield [ // namespace with wrong casing ' 'callable', 'T_FINALLY' => 'finally', 'T_INSTEADOF' => 'insteadof', 'T_TRAIT' => 'trait', 'T_TRAIT_C' => '__TRAIT__', ] as $tokenType => $tokenValue) { if (\defined($tokenType)) { $cases[] = $tokenValue.'.php'; $cases[] = strtolower($tokenValue).'.php'; } } return array_map(static fn ($case): array => [ ' [ ' [ ' [ ' [ 'doTest($expected, $input); } public static function provideFix80Cases(): iterable { yield 'anonymous + annotation' => [ 'doTest($expected, $input, self::getTestFile(__FILE__)); } public static function provideFix81Cases(): iterable { yield 'enum with wrong casing' => [ '