ExceptionComparator.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  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. /**
  12. * Compares Exception instances for equality.
  13. */
  14. class ExceptionComparator extends ObjectComparator
  15. {
  16. /**
  17. * Returns whether the comparator can compare two values.
  18. *
  19. * @param mixed $expected The first value to compare
  20. * @param mixed $actual The second value to compare
  21. *
  22. * @return bool
  23. */
  24. public function accepts($expected, $actual)
  25. {
  26. return $expected instanceof \Exception && $actual instanceof \Exception;
  27. }
  28. /**
  29. * Converts an object to an array containing all of its private, protected
  30. * and public properties.
  31. *
  32. * @param object $object
  33. *
  34. * @return array
  35. */
  36. protected function toArray($object)
  37. {
  38. $array = parent::toArray($object);
  39. unset(
  40. $array['file'],
  41. $array['line'],
  42. $array['trace'],
  43. $array['string'],
  44. $array['xdebug_message']
  45. );
  46. return $array;
  47. }
  48. }