FixerDefinitionTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\FixerDefinition;
  13. use PhpCsFixer\FixerDefinition\CodeSampleInterface;
  14. use PhpCsFixer\FixerDefinition\FixerDefinition;
  15. use PhpCsFixer\Tests\TestCase;
  16. /**
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\FixerDefinition\FixerDefinition
  20. */
  21. final class FixerDefinitionTest extends TestCase
  22. {
  23. public function testGetSummary(): void
  24. {
  25. $definition = new FixerDefinition('Foo', []);
  26. self::assertSame('Foo', $definition->getSummary());
  27. }
  28. public function testGetCodeSamples(): void
  29. {
  30. $samples = [
  31. $this->createCodeSampleDouble(),
  32. $this->createCodeSampleDouble(),
  33. ];
  34. $definition = new FixerDefinition('', $samples);
  35. self::assertSame($samples, $definition->getCodeSamples());
  36. }
  37. public function testGetDescription(): void
  38. {
  39. $definition = new FixerDefinition('', []);
  40. self::assertNull($definition->getDescription());
  41. $definition = new FixerDefinition('', [], 'Foo');
  42. self::assertSame('Foo', $definition->getDescription());
  43. }
  44. public function testGetRiskyDescription(): void
  45. {
  46. $definition = new FixerDefinition('', []);
  47. self::assertNull($definition->getRiskyDescription());
  48. $definition = new FixerDefinition('', [], null, 'Foo');
  49. self::assertSame('Foo', $definition->getRiskyDescription());
  50. }
  51. private function createCodeSampleDouble(): CodeSampleInterface
  52. {
  53. return new class implements CodeSampleInterface {
  54. public function getCode(): string
  55. {
  56. throw new \LogicException('Not implemented.');
  57. }
  58. public function getConfiguration(): ?array
  59. {
  60. throw new \LogicException('Not implemented.');
  61. }
  62. };
  63. }
  64. }