Comparator.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. use SebastianBergmann\Exporter\Exporter;
  12. /**
  13. * Abstract base class for comparators which compare values for equality.
  14. */
  15. abstract class Comparator
  16. {
  17. /**
  18. * @var Factory
  19. */
  20. protected $factory;
  21. /**
  22. * @var Exporter
  23. */
  24. protected $exporter;
  25. public function __construct()
  26. {
  27. $this->exporter = new Exporter;
  28. }
  29. /**
  30. * @param Factory $factory
  31. */
  32. public function setFactory(Factory $factory)
  33. {
  34. $this->factory = $factory;
  35. }
  36. /**
  37. * Returns whether the comparator can compare two values.
  38. *
  39. * @param mixed $expected The first value to compare
  40. * @param mixed $actual The second value to compare
  41. *
  42. * @return bool
  43. */
  44. abstract public function accepts($expected, $actual);
  45. /**
  46. * Asserts that two values are equal.
  47. *
  48. * @param mixed $expected First value to compare
  49. * @param mixed $actual Second value to compare
  50. * @param float $delta Allowed numerical distance between two values to consider them equal
  51. * @param bool $canonicalize Arrays are sorted before comparison when set to true
  52. * @param bool $ignoreCase Case is ignored when set to true
  53. *
  54. * @throws ComparisonFailure
  55. */
  56. abstract public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false);
  57. }