InvalidFixerConfigurationExceptionTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\InvalidConfigurationException;
  14. use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
  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\InvalidFixerConfigurationException
  23. */
  24. final class InvalidFixerConfigurationExceptionTest extends TestCase
  25. {
  26. public function testIsInvalidArgumentException(): void
  27. {
  28. $exception = new InvalidFixerConfigurationException('foo', 'I cannot do that, Dave.');
  29. self::assertInstanceOf(InvalidConfigurationException::class, $exception);
  30. }
  31. public function testDefaults(): void
  32. {
  33. $fixerName = 'hal';
  34. $message = 'I cannot do that, Dave.';
  35. $exception = new InvalidFixerConfigurationException(
  36. $fixerName,
  37. $message
  38. );
  39. self::assertSame(sprintf('[%s] %s', $fixerName, $message), $exception->getMessage());
  40. self::assertSame(FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG, $exception->getCode());
  41. self::assertSame($fixerName, $exception->getFixerName());
  42. self::assertNull($exception->getPrevious());
  43. }
  44. public function testConstructorSetsValues(): void
  45. {
  46. $fixerName = 'hal';
  47. $message = 'I cannot do that, Dave.';
  48. $previous = new \RuntimeException();
  49. $exception = new InvalidFixerConfigurationException(
  50. $fixerName,
  51. $message,
  52. $previous
  53. );
  54. self::assertSame(sprintf('[%s] %s', $fixerName, $message), $exception->getMessage());
  55. self::assertSame(FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG, $exception->getCode());
  56. self::assertSame($fixerName, $exception->getFixerName());
  57. self::assertSame($previous, $exception->getPrevious());
  58. }
  59. }