ResourceComparator.php 1.6 KB

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