InvalidFixerConfigurationExceptionTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\ConfigurationException;
  13. use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
  14. use PhpCsFixer\Console\Command\FixCommandExitStatusCalculator;
  15. use PhpCsFixer\Tests\TestCase;
  16. /**
  17. * @author Andreas Möller <am@localheinz.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
  22. */
  23. final class InvalidFixerConfigurationExceptionTest extends TestCase
  24. {
  25. public function testDefaults(): void
  26. {
  27. $fixerName = 'hal';
  28. $message = 'I cannot do that, Dave.';
  29. $exception = new InvalidFixerConfigurationException(
  30. $fixerName,
  31. $message
  32. );
  33. self::assertSame(\sprintf('[%s] %s', $fixerName, $message), $exception->getMessage());
  34. self::assertSame(FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG, $exception->getCode());
  35. self::assertSame($fixerName, $exception->getFixerName());
  36. self::assertNull($exception->getPrevious());
  37. }
  38. public function testConstructorSetsValues(): void
  39. {
  40. $fixerName = 'hal';
  41. $message = 'I cannot do that, Dave.';
  42. $previous = new \RuntimeException();
  43. $exception = new InvalidFixerConfigurationException(
  44. $fixerName,
  45. $message,
  46. $previous
  47. );
  48. self::assertSame(\sprintf('[%s] %s', $fixerName, $message), $exception->getMessage());
  49. self::assertSame(FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG, $exception->getCode());
  50. self::assertSame($fixerName, $exception->getFixerName());
  51. self::assertSame($previous, $exception->getPrevious());
  52. }
  53. }