summaryrefslogtreecommitdiffstatshomepage
path: root/tests/phpunit/includes/phpunit7
diff options
context:
space:
mode:
authorSergey Biryukov <sergeybiryukov@git.wordpress.org>2020-09-07 03:12:17 +0000
committerSergey Biryukov <sergeybiryukov@git.wordpress.org>2020-09-07 03:12:17 +0000
commit5bad67bccf129b731b998e5a34437427bed6f3b1 (patch)
treeb983c63901c6bdd030936a728f62c5d16aecc76f /tests/phpunit/includes/phpunit7
parent84d524e18964e928ba69d02b248b06fab524a8bf (diff)
downloadwordpress-5bad67bccf129b731b998e5a34437427bed6f3b1.tar.gz
wordpress-5bad67bccf129b731b998e5a34437427bed6f3b1.zip
Tests: Add a polyfill for `assertEqualsWithDelta()` to `WP_UnitTestCase` and use it where appropriate.
`assertEqualsWithDelta()` was added in PHPUnit 7.5, while WordPress still supports PHPUnit 5.4.x as the minimum version. See #38266. git-svn-id: https://develop.svn.wordpress.org/trunk@48952 602fd350-edb4-49c9-b593-d223f7449a82
Diffstat (limited to 'tests/phpunit/includes/phpunit7')
-rw-r--r--tests/phpunit/includes/phpunit7/testcase.php29
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/phpunit/includes/phpunit7/testcase.php b/tests/phpunit/includes/phpunit7/testcase.php
index 84fe88fe3e..44362d835d 100644
--- a/tests/phpunit/includes/phpunit7/testcase.php
+++ b/tests/phpunit/includes/phpunit7/testcase.php
@@ -16,8 +16,8 @@ class WP_UnitTestCase extends WP_UnitTestCase_Base {
/**
* Asserts that a condition is not false.
*
- * This method has been backported from a more recent PHPUnit version, as tests running on PHP 5.2 use
- * PHPUnit 3.6.x.
+ * This method has been backported from a more recent PHPUnit version,
+ * as tests running on PHP 5.2 use PHPUnit 3.6.x.
*
* @since 4.7.4
*
@@ -29,4 +29,29 @@ class WP_UnitTestCase extends WP_UnitTestCase_Base {
public static function assertNotFalse( $condition, string $message = '' ): void {
self::assertThat( $condition, self::logicalNot( self::isFalse() ), $message );
}
+
+ /**
+ * Asserts that two variables are equal (with delta).
+ *
+ * This method has been backported from a more recent PHPUnit version,
+ * as tests running on PHP 5.6 use PHPUnit 5.7.x.
+ *
+ * @since 5.6.0
+ *
+ * @param mixed $expected First value to compare.
+ * @param mixed $actual Second value to compare.
+ * @param float $delta Allowed numerical distance between two values to consider them equal.
+ * @param string $message Optional. Message to display when the assertion fails.
+ *
+ * @throws ExpectationFailedException
+ * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
+ */
+ public static function assertEqualsWithDelta( $expected, $actual, float $delta, string $message = '' ): void {
+ $constraint = new PHPUnit\Framework\Constraint\IsEqual(
+ $expected,
+ $delta
+ );
+
+ static::assertThat( $actual, $constraint, $message );
+ }
}