InvalidConfigurationExceptionTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\ConfigurationException;
  12. use PhpCsFixer\ConfigurationException\InvalidConfigurationException;
  13. use PhpCsFixer\Console\Command\FixCommandExitStatusCalculator;
  14. use PhpCsFixer\Tests\TestCase;
  15. /**
  16. * @author Andreas Möller <am@localheinz.com>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\ConfigurationException\InvalidConfigurationException
  21. */
  22. final class InvalidConfigurationExceptionTest extends TestCase
  23. {
  24. public function testIsInvalidArgumentException()
  25. {
  26. $exception = new InvalidConfigurationException('I cannot do that, Dave.');
  27. static::assertInstanceOf(\InvalidArgumentException::class, $exception);
  28. }
  29. public function testDefaults()
  30. {
  31. $message = 'I cannot do that, Dave.';
  32. $exception = new InvalidConfigurationException($message);
  33. static::assertSame($message, $exception->getMessage());
  34. static::assertSame(FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_CONFIG, $exception->getCode());
  35. static::assertNull($exception->getPrevious());
  36. }
  37. public function testConstructorSetsValues()
  38. {
  39. $message = 'I cannot do that, Dave.';
  40. $code = 9000;
  41. $previous = new \RuntimeException();
  42. $exception = new InvalidConfigurationException(
  43. $message,
  44. $code,
  45. $previous
  46. );
  47. static::assertSame($message, $exception->getMessage());
  48. static::assertSame($code, $exception->getCode());
  49. static::assertSame($previous, $exception->getPrevious());
  50. }
  51. }