testcase.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. require_once dirname( __DIR__ ) . '/abstract-testcase.php';
  3. /**
  4. * Defines a basic fixture to run multiple tests.
  5. *
  6. * Resets the state of the WordPress installation before and after every test.
  7. *
  8. * Includes utility functions and assertions useful for testing WordPress.
  9. *
  10. * All WordPress unit tests should inherit from this class.
  11. */
  12. class WP_UnitTestCase extends WP_UnitTestCase_Base {
  13. /**
  14. * Asserts that two variables are equal (with delta).
  15. *
  16. * This method has been backported from a more recent PHPUnit version,
  17. * as tests running on PHP 5.6 use PHPUnit 5.7.x.
  18. *
  19. * @since 5.6.0
  20. *
  21. * @param mixed $expected First value to compare.
  22. * @param mixed $actual Second value to compare.
  23. * @param float $delta Allowed numerical distance between two values to consider them equal.
  24. * @param string $message Optional. Message to display when the assertion fails.
  25. *
  26. * @throws ExpectationFailedException
  27. * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
  28. */
  29. public static function assertEqualsWithDelta( $expected, $actual, float $delta, string $message = '' ): void {
  30. $constraint = new PHPUnit\Framework\Constraint\IsEqual(
  31. $expected,
  32. $delta
  33. );
  34. static::assertThat( $actual, $constraint, $message );
  35. }
  36. }