InvalidFixerConfigurationExceptionTest.php 2.1 KB

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