RequiredFixerConfigurationExceptionTest.php 2.2 KB

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