ResourceComparator.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 assert;
  12. use function is_resource;
  13. use SebastianBergmann\Exporter\Exporter;
  14. final class ResourceComparator extends Comparator
  15. {
  16. public function accepts(mixed $expected, mixed $actual): bool
  17. {
  18. return is_resource($expected) && is_resource($actual);
  19. }
  20. /**
  21. * @throws ComparisonFailure
  22. */
  23. public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false): void
  24. {
  25. assert(is_resource($expected));
  26. assert(is_resource($actual));
  27. $exporter = new Exporter;
  28. if ($actual != $expected) {
  29. throw new ComparisonFailure(
  30. $expected,
  31. $actual,
  32. $exporter->export($expected),
  33. $exporter->export($actual)
  34. );
  35. }
  36. }
  37. }