AbstractFixerTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests;
  13. use PhpCsFixer\Tests\Fixtures\Test\AbstractFixerTest\UnconfigurableFixer;
  14. use PhpCsFixer\WhitespacesFixerConfig;
  15. /**
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\AbstractFixer
  19. */
  20. final class AbstractFixerTest extends TestCase
  21. {
  22. public function testConfigureUnconfigurable(): void
  23. {
  24. $fixer = new UnconfigurableFixer();
  25. static::assertSame(0, $fixer->getPriority());
  26. static::assertSame('unconfigurable', $fixer->getName());
  27. $this->expectException(\LogicException::class);
  28. $this->expectExceptionMessage('Cannot configure using Abstract parent, child not implementing "PhpCsFixer\Fixer\ConfigurableFixerInterface".');
  29. $fixer->configure(['foo' => 'bar']);
  30. }
  31. public function testGetConfigurationDefinitionUnconfigurable(): void
  32. {
  33. $fixer = new UnconfigurableFixer();
  34. $this->expectException(\LogicException::class);
  35. $this->expectExceptionMessage(sprintf('Cannot get configuration definition using Abstract parent, child "%s" not implementing "PhpCsFixer\Fixer\ConfigurableFixerInterface".', \get_class($fixer)));
  36. $fixer->getConfigurationDefinition();
  37. }
  38. public function testCreateConfigurationDefinitionUnconfigurable(): void
  39. {
  40. $fixer = new UnconfigurableFixer();
  41. $this->expectException(\LogicException::class);
  42. $this->expectExceptionMessage('Cannot create configuration definition using Abstract parent, child not implementing "PhpCsFixer\Fixer\ConfigurableFixerInterface".');
  43. $fixer->doSomethingWithCreateConfigDefinition();
  44. }
  45. public function testSetWhitespacesConfigUnconfigurable(): void
  46. {
  47. $fixer = new UnconfigurableFixer();
  48. $this->expectException(\LogicException::class);
  49. $this->expectExceptionMessage('Cannot run method for class not implementing "PhpCsFixer\Fixer\WhitespacesAwareFixerInterface".');
  50. $fixer->setWhitespacesConfig(new WhitespacesFixerConfig());
  51. }
  52. }