CommandIsSuccessful.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. public function toString(): string
  16. {
  17. return 'is successful';
  18. }
  19. protected function matches($other): bool
  20. {
  21. return Command::SUCCESS === $other;
  22. }
  23. protected function failureDescription($other): string
  24. {
  25. return 'the command '.$this->toString();
  26. }
  27. protected function additionalFailureDescription($other): string
  28. {
  29. $mapping = [
  30. Command::FAILURE => 'Command failed.',
  31. Command::INVALID => 'Command was invalid.',
  32. ];
  33. return $mapping[$other] ?? sprintf('Command returned exit status %d.', $other);
  34. }
  35. }