CommandIsSuccessful.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Tester\Constraint;
  11. use PHPUnit\Framework\Constraint\Constraint;
  12. use Symfony\Component\Console\Command\Command;
  13. final class CommandIsSuccessful extends Constraint
  14. {
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public function toString(): string
  19. {
  20. return 'is successful';
  21. }
  22. /**
  23. * {@inheritdoc}
  24. */
  25. protected function matches($other): bool
  26. {
  27. return Command::SUCCESS === $other;
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. protected function failureDescription($other): string
  33. {
  34. return 'the command '.$this->toString();
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. protected function additionalFailureDescription($other): string
  40. {
  41. $mapping = [
  42. Command::FAILURE => 'Command failed.',
  43. Command::INVALID => 'Command was invalid.',
  44. ];
  45. return $mapping[$other] ?? sprintf('Command returned exit status %d.', $other);
  46. }
  47. }