123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?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;
- use PhpCsFixer\AbstractFixer;
- use PhpCsFixer\AccessibleObject\AccessibleObject;
- use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
- use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
- use PhpCsFixer\Tokenizer\Tokens;
- use PhpCsFixer\WhitespacesFixerConfig;
- /**
- * @internal
- *
- * @covers \PhpCsFixer\AbstractFixer
- */
- final class AbstractFixerTest extends TestCase
- {
- public function testDefaults(): void
- {
- $fixer = $this->createUnconfigurableFixerDouble();
- self::assertFalse($fixer->isRisky());
- self::assertTrue($fixer->supports(new \SplFileInfo(__FILE__)));
- }
- public function testSetWhitespacesConfigUnconfigurable(): void
- {
- $fixer = $this->createUnconfigurableFixerDouble();
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('Cannot run method for class not implementing "PhpCsFixer\Fixer\WhitespacesAwareFixerInterface".');
- $fixer->setWhitespacesConfig(new WhitespacesFixerConfig());
- }
- public function testGetWhitespacesFixerConfig(): void
- {
- $fixer = $this->createWhitespacesAwareFixerDouble();
- $config = AccessibleObject::create($fixer)->whitespacesConfig;
- self::assertSame(' ', $config->getIndent());
- self::assertSame("\n", $config->getLineEnding());
- $newConfig = new WhitespacesFixerConfig("\t", "\r\n");
- $fixer->setWhitespacesConfig($newConfig);
- $config = AccessibleObject::create($fixer)->whitespacesConfig;
- self::assertSame("\t", $config->getIndent());
- self::assertSame("\r\n", $config->getLineEnding());
- }
- private function createWhitespacesAwareFixerDouble(): WhitespacesAwareFixerInterface
- {
- return new class extends AbstractFixer implements WhitespacesAwareFixerInterface {
- public function getDefinition(): FixerDefinitionInterface
- {
- throw new \BadMethodCallException('Not implemented.');
- }
- public function isCandidate(Tokens $tokens): bool
- {
- throw new \BadMethodCallException('Not implemented.');
- }
- protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
- {
- throw new \BadMethodCallException('Not implemented.');
- }
- };
- }
- private function createUnconfigurableFixerDouble(): AbstractFixer
- {
- return new class extends AbstractFixer {
- public function getDefinition(): FixerDefinitionInterface
- {
- throw new \LogicException('Not implemented.');
- }
- public function isCandidate(Tokens $tokens): bool
- {
- return true;
- }
- protected function applyFix(\SplFileInfo $file, Tokens $tokens): void {}
- };
- }
- }
|