ExceptionComparator.php 976 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of sebastian/comparator.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  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 SebastianBergmann\Comparator;
  11. use function assert;
  12. use Exception;
  13. /**
  14. * Compares Exception instances for equality.
  15. */
  16. final class ExceptionComparator extends ObjectComparator
  17. {
  18. public function accepts(mixed $expected, mixed $actual): bool
  19. {
  20. return $expected instanceof Exception && $actual instanceof Exception;
  21. }
  22. protected function toArray(object $object): array
  23. {
  24. assert($object instanceof Exception);
  25. $array = parent::toArray($object);
  26. unset(
  27. $array['file'],
  28. $array['line'],
  29. $array['trace'],
  30. $array['string'],
  31. $array['xdebug_message']
  32. );
  33. return $array;
  34. }
  35. }