MockObjectComparator.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 PHPUnit_Framework_MockObject_MockObject instances for equality.
  13. */
  14. class MockObjectComparator 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 \PHPUnit_Framework_MockObject_MockObject || $expected instanceof \PHPUnit\Framework\MockObject\MockObject) &&
  27. ($actual instanceof \PHPUnit_Framework_MockObject_MockObject || $actual instanceof \PHPUnit\Framework\MockObject\MockObject);
  28. }
  29. /**
  30. * Converts an object to an array containing all of its private, protected
  31. * and public properties.
  32. *
  33. * @param object $object
  34. *
  35. * @return array
  36. */
  37. protected function toArray($object)
  38. {
  39. $array = parent::toArray($object);
  40. unset($array['__phpunit_invocationMocker']);
  41. return $array;
  42. }
  43. }