菜谱项目

SplObjectStorageComparator.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /*
  3. * This file is part of the Comparator package.
  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 \SplObjectStorage instances for equality.
  13. */
  14. class SplObjectStorageComparator extends Comparator
  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. * @return bool
  22. */
  23. public function accepts($expected, $actual)
  24. {
  25. return $expected instanceof \SplObjectStorage && $actual instanceof \SplObjectStorage;
  26. }
  27. /**
  28. * Asserts that two values are equal.
  29. *
  30. * @param mixed $expected First value to compare
  31. * @param mixed $actual Second value to compare
  32. * @param float $delta Allowed numerical distance between two values to consider them equal
  33. * @param bool $canonicalize Arrays are sorted before comparison when set to true
  34. * @param bool $ignoreCase Case is ignored when set to true
  35. *
  36. * @throws ComparisonFailure
  37. */
  38. public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false)
  39. {
  40. foreach ($actual as $object) {
  41. if (!$expected->contains($object)) {
  42. throw new ComparisonFailure(
  43. $expected,
  44. $actual,
  45. $this->exporter->export($expected),
  46. $this->exporter->export($actual),
  47. false,
  48. 'Failed asserting that two objects are equal.'
  49. );
  50. }
  51. }
  52. foreach ($expected as $object) {
  53. if (!$actual->contains($object)) {
  54. throw new ComparisonFailure(
  55. $expected,
  56. $actual,
  57. $this->exporter->export($expected),
  58. $this->exporter->export($actual),
  59. false,
  60. 'Failed asserting that two objects are equal.'
  61. );
  62. }
  63. }
  64. }
  65. }