ResourceComparator.php 1.5 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 resources for equality.
  13. */
  14. class ResourceComparator 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. *
  22. * @return bool
  23. */
  24. public function accepts($expected, $actual)
  25. {
  26. return \is_resource($expected) && \is_resource($actual);
  27. }
  28. /**
  29. * Asserts that two values are equal.
  30. *
  31. * @param mixed $expected First value to compare
  32. * @param mixed $actual Second value to compare
  33. * @param float $delta Allowed numerical distance between two values to consider them equal
  34. * @param bool $canonicalize Arrays are sorted before comparison when set to true
  35. * @param bool $ignoreCase Case is ignored when set to true
  36. *
  37. * @throws ComparisonFailure
  38. */
  39. public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false)
  40. {
  41. if ($actual != $expected) {
  42. throw new ComparisonFailure(
  43. $expected,
  44. $actual,
  45. $this->exporter->export($expected),
  46. $this->exporter->export($actual)
  47. );
  48. }
  49. }
  50. }