summaryrefslogtreecommitdiffstatshomepage
path: root/tests/phpunit
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
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')
-rw-r--r--tests/phpunit/includes/phpunit6/compat.php1
-rw-r--r--tests/phpunit/includes/phpunit7/testcase.php29
-rw-r--r--tests/phpunit/includes/testcase.php29
-rw-r--r--tests/phpunit/tests/date/currentTime.php32
-rw-r--r--tests/phpunit/tests/date/dateI18n.php16
-rw-r--r--tests/phpunit/tests/date/getFeedBuildDate.php12
-rw-r--r--tests/phpunit/tests/date/query.php6
-rw-r--r--tests/phpunit/tests/formatting/date.php4
-rw-r--r--tests/phpunit/tests/media.php8
-rw-r--r--tests/phpunit/tests/multisite/site.php10
-rw-r--r--tests/phpunit/tests/post.php2
-rw-r--r--tests/phpunit/tests/rest-api/rest-posts-controller.php10
12 files changed, 105 insertions, 54 deletions
diff --git a/tests/phpunit/includes/phpunit6/compat.php b/tests/phpunit/includes/phpunit6/compat.php
index dcc99e9a76..61aa6048e9 100644
--- a/tests/phpunit/includes/phpunit6/compat.php
+++ b/tests/phpunit/includes/phpunit6/compat.php
@@ -11,6 +11,7 @@ if ( class_exists( 'PHPUnit\Runner\Version' ) && version_compare( PHPUnit\Runner
class_alias( 'PHPUnit\Framework\Test', 'PHPUnit_Framework_Test' );
class_alias( 'PHPUnit\Framework\Warning', 'PHPUnit_Framework_Warning' );
class_alias( 'PHPUnit\Framework\AssertionFailedError', 'PHPUnit_Framework_AssertionFailedError' );
+ class_alias( 'PHPUnit\Framework\Constraint\IsEqual', 'PHPUnit_Framework_Constraint_IsEqual' );
class_alias( 'PHPUnit\Framework\TestSuite', 'PHPUnit_Framework_TestSuite' );
class_alias( 'PHPUnit\Framework\TestListener', 'PHPUnit_Framework_TestListener' );
class_alias( 'PHPUnit\Util\GlobalState', 'PHPUnit_Util_GlobalState' );
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 );
+ }
}
diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php
index 7689d0e48c..068998ae04 100644
--- a/tests/phpunit/includes/testcase.php
+++ b/tests/phpunit/includes/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, $message = '' ) {
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, $delta, $message = '' ) {
+ $constraint = new PHPUnit_Framework_Constraint_IsEqual(
+ $expected,
+ $delta
+ );
+
+ static::assertThat( $actual, $constraint, $message );
+ }
}
diff --git a/tests/phpunit/tests/date/currentTime.php b/tests/phpunit/tests/date/currentTime.php
index 490a8c9070..a0b03c3fd5 100644
--- a/tests/phpunit/tests/date/currentTime.php
+++ b/tests/phpunit/tests/date/currentTime.php
@@ -16,8 +16,8 @@ class Tests_Date_Current_Time extends WP_UnitTestCase {
$timestamp = time();
$wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS;
- $this->assertEquals( strtotime( gmdate( $format ) ), strtotime( current_time( $format, true ) ), 'The dates should be equal', 2 );
- $this->assertEquals( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( $format ) ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( gmdate( $format ) ), strtotime( current_time( $format, true ) ), 2, 'The dates should be equal' );
+ $this->assertEqualsWithDelta( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( $format ) ), 2, 'The dates should be equal' );
}
/**
@@ -30,8 +30,8 @@ class Tests_Date_Current_Time extends WP_UnitTestCase {
$timestamp = time();
$wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS;
- $this->assertEquals( strtotime( gmdate( $format ) ), strtotime( current_time( 'mysql', true ) ), 'The dates should be equal', 2 );
- $this->assertEquals( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( 'mysql' ) ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( gmdate( $format ) ), strtotime( current_time( 'mysql', true ) ), 2, 'The dates should be equal' );
+ $this->assertEqualsWithDelta( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( 'mysql' ) ), 2, 'The dates should be equal' );
}
/**
@@ -44,9 +44,9 @@ class Tests_Date_Current_Time extends WP_UnitTestCase {
$wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS;
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC
- $this->assertEquals( $timestamp, current_time( 'timestamp', true ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( $timestamp, current_time( 'timestamp', true ), 2, 'The dates should be equal' );
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
- $this->assertEquals( $wp_timestamp, current_time( 'timestamp' ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( $wp_timestamp, current_time( 'timestamp' ), 2, 'The dates should be equal' );
}
/**
@@ -70,10 +70,10 @@ class Tests_Date_Current_Time extends WP_UnitTestCase {
$current_time_gmt = current_time( $format, true );
$current_time = current_time( $format );
- $this->assertEquals( strtotime( gmdate( $format ) ), strtotime( $current_time_custom_timezone_gmt ), 'The dates should be equal', 2 );
- $this->assertEquals( strtotime( $datetime->format( $format ) ), strtotime( $current_time_custom_timezone ), 'The dates should be equal', 2 );
- $this->assertEquals( strtotime( gmdate( $format ) ), strtotime( $current_time_gmt ), 'The dates should be equal', 2 );
- $this->assertEquals( strtotime( $datetime->format( $format ) ), strtotime( $current_time ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( gmdate( $format ) ), strtotime( $current_time_custom_timezone_gmt ), 2, 'The dates should be equal' );
+ $this->assertEqualsWithDelta( strtotime( $datetime->format( $format ) ), strtotime( $current_time_custom_timezone ), 2, 'The dates should be equal' );
+ $this->assertEqualsWithDelta( strtotime( gmdate( $format ) ), strtotime( $current_time_gmt ), 2, 'The dates should be equal' );
+ $this->assertEqualsWithDelta( strtotime( $datetime->format( $format ) ), strtotime( $current_time ), 2, 'The dates should be equal' );
}
/**
@@ -88,14 +88,14 @@ class Tests_Date_Current_Time extends WP_UnitTestCase {
$wp_timestamp = $timestamp + $datetime->getOffset();
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC
- $this->assertEquals( $timestamp, current_time( 'timestamp', true ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( $timestamp, current_time( 'timestamp', true ), 2, 'The dates should be equal' );
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC
- $this->assertEquals( $timestamp, current_time( 'U', true ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( $timestamp, current_time( 'U', true ), 2, 'The dates should be equal' );
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
- $this->assertEquals( $wp_timestamp, current_time( 'timestamp' ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( $wp_timestamp, current_time( 'timestamp' ), 2, 'The dates should be equal' );
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
- $this->assertEquals( $wp_timestamp, current_time( 'U' ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( $wp_timestamp, current_time( 'U' ), 2, 'The dates should be equal' );
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
$this->assertInternalType( 'int', current_time( 'timestamp' ) );
@@ -113,7 +113,7 @@ class Tests_Date_Current_Time extends WP_UnitTestCase {
$datetime_utc = new DateTime( '@' . $timestamp );
$datetime_utc->setTimezone( new DateTimeZone( 'UTC' ) );
- $this->assertEquals( strtotime( $datetime_local->format( DATE_W3C ) ), strtotime( current_time( DATE_W3C ) ), 'The dates should be equal', 2 );
- $this->assertEquals( strtotime( $datetime_utc->format( DATE_W3C ) ), strtotime( current_time( DATE_W3C, true ) ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( $datetime_local->format( DATE_W3C ) ), strtotime( current_time( DATE_W3C ) ), 2, 'The dates should be equal' );
+ $this->assertEqualsWithDelta( strtotime( $datetime_utc->format( DATE_W3C ) ), strtotime( current_time( DATE_W3C, true ) ), 2, 'The dates should be equal' );
}
}
diff --git a/tests/phpunit/tests/date/dateI18n.php b/tests/phpunit/tests/date/dateI18n.php
index 0a81990d63..5904a23051 100644
--- a/tests/phpunit/tests/date/dateI18n.php
+++ b/tests/phpunit/tests/date/dateI18n.php
@@ -16,7 +16,7 @@ class Tests_Date_I18n extends WP_UnitTestCase {
$datetime = new DateTime( 'now', new DateTimeZone( $timezone ) );
$wp_timestamp = $datetime->getTimestamp() + $datetime->getOffset();
- $this->assertEquals( $wp_timestamp, date_i18n( 'U', 'invalid' ), '', 5 );
+ $this->assertEqualsWithDelta( $wp_timestamp, date_i18n( 'U', 'invalid' ), 5, 'The dates should be equal' );
}
/**
@@ -38,7 +38,7 @@ class Tests_Date_I18n extends WP_UnitTestCase {
}
public function test_should_format_date() {
- $this->assertEquals( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( date_i18n( 'Y-m-d H:i:s' ) ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( date_i18n( 'Y-m-d H:i:s' ) ), 2, 'The dates should be equal' );
}
public function test_should_use_custom_timestamp() {
@@ -46,19 +46,19 @@ class Tests_Date_I18n extends WP_UnitTestCase {
}
public function test_date_should_be_in_gmt() {
- $this->assertEquals( strtotime( gmdate( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( gmdate( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 2, 'The dates should be equal' );
}
public function test_custom_timezone_setting() {
update_option( 'timezone_string', 'America/Regina' );
- $this->assertEquals( strtotime( gmdate( 'Y-m-d H:i:s', time() + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ), strtotime( date_i18n( 'Y-m-d H:i:s' ) ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s', time() + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ), strtotime( date_i18n( 'Y-m-d H:i:s' ) ), 2, 'The dates should be equal' );
}
public function test_date_should_be_in_gmt_with_custom_timezone_setting() {
update_option( 'timezone_string', 'America/Regina' );
- $this->assertEquals( strtotime( gmdate( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( gmdate( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 2, 'The dates should be equal' );
}
public function test_date_should_be_in_gmt_with_custom_timezone_setting_and_timestamp() {
@@ -121,7 +121,7 @@ class Tests_Date_I18n extends WP_UnitTestCase {
public function test_date_i18n_handles_shorthand_formats( $short, $full ) {
update_option( 'timezone_string', 'America/Regina' );
- $this->assertEquals( strtotime( date_i18n( $full ) ), strtotime( date_i18n( $short ) ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( date_i18n( $full ) ), strtotime( date_i18n( $short ) ), 2, 'The dates should be equal' );
$this->assertSame( $short, date_i18n( '\\' . $short ) );
}
@@ -148,8 +148,8 @@ class Tests_Date_I18n extends WP_UnitTestCase {
$timestamp = $datetime->getTimestamp();
$wp_timestamp = $timestamp + $datetime->getOffset();
- $this->assertEquals( $wp_timestamp, date_i18n( 'U' ), 'The dates should be equal', 2 );
- $this->assertEquals( $timestamp, date_i18n( 'U', false, true ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( $wp_timestamp, date_i18n( 'U' ), 2, 'The dates should be equal' );
+ $this->assertEqualsWithDelta( $timestamp, date_i18n( 'U', false, true ), 2, 'The dates should be equal' );
$this->assertSame( $wp_timestamp, date_i18n( 'U', $wp_timestamp ) );
}
diff --git a/tests/phpunit/tests/date/getFeedBuildDate.php b/tests/phpunit/tests/date/getFeedBuildDate.php
index 31a825a394..6fcd2fdbd4 100644
--- a/tests/phpunit/tests/date/getFeedBuildDate.php
+++ b/tests/phpunit/tests/date/getFeedBuildDate.php
@@ -60,11 +60,11 @@ class Tests_Date_Get_Feed_Build_Date extends WP_UnitTestCase {
)
);
- $this->assertEquals(
+ $this->assertEqualsWithDelta(
strtotime( $datetime_utc->format( DATE_RFC3339 ) ),
strtotime( get_feed_build_date( DATE_RFC3339 ) ),
- 'Fall back to time of last post modified with no posts',
- 2
+ 2,
+ 'Fall back to time of last post modified with no posts'
);
$post_id_broken = $this->factory->post->create();
@@ -74,11 +74,11 @@ class Tests_Date_Get_Feed_Build_Date extends WP_UnitTestCase {
$wp_query->posts = array( $post_broken );
- $this->assertEquals(
+ $this->assertEqualsWithDelta(
strtotime( $datetime_utc->format( DATE_RFC3339 ) ),
strtotime( get_feed_build_date( DATE_RFC3339 ) ),
- 'Fall back to time of last post modified with broken post object',
- 2
+ 2,
+ 'Fall back to time of last post modified with broken post object'
);
}
}
diff --git a/tests/phpunit/tests/date/query.php b/tests/phpunit/tests/date/query.php
index 187979606a..0445fd819f 100644
--- a/tests/phpunit/tests/date/query.php
+++ b/tests/phpunit/tests/date/query.php
@@ -524,7 +524,7 @@ class Tests_WP_Date_Query extends WP_UnitTestCase {
$found = $q->build_mysql_datetime( $datetime, $default_to_max );
$message = "Expected {$expected}, got {$found}";
- $this->assertEquals( strtotime( $expected ), strtotime( $found ), $message, 10 );
+ $this->assertEqualsWithDelta( strtotime( $expected ), strtotime( $found ), 10, $message );
}
public function mysql_datetime_input_provider() {
@@ -559,7 +559,7 @@ class Tests_WP_Date_Query extends WP_UnitTestCase {
$found = $q->build_mysql_datetime( $datetime, $default_to_max );
$message = "Expected {$expected}, got {$found}";
- $this->assertEquals( strtotime( $expected ), strtotime( $found ), $message, 10 );
+ $this->assertEqualsWithDelta( strtotime( $expected ), strtotime( $found ), 10, $message );
}
@@ -583,7 +583,7 @@ class Tests_WP_Date_Query extends WP_UnitTestCase {
$found = $q->build_mysql_datetime( '-1 day' );
$message = "Expected {$expected}, got {$found}";
- $this->assertEquals( strtotime( $expected ), strtotime( $found ), $message, 10 );
+ $this->assertEqualsWithDelta( strtotime( $expected ), strtotime( $found ), 10, $message );
}
public function test_build_time_query_insufficient_time_values() {
diff --git a/tests/phpunit/tests/formatting/date.php b/tests/phpunit/tests/formatting/date.php
index ac87159996..9b540929e0 100644
--- a/tests/phpunit/tests/formatting/date.php
+++ b/tests/phpunit/tests/formatting/date.php
@@ -85,7 +85,7 @@ class Tests_Formatting_Date extends WP_UnitTestCase {
update_option( 'timezone_string', 'Europe/London' );
$local = 'now';
$gmt = gmdate( 'Y-m-d H:i:s' );
- $this->assertEquals( strtotime( $gmt ), strtotime( get_gmt_from_date( $local ) ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( $gmt ), strtotime( get_gmt_from_date( $local ) ), 2, 'The dates should be equal' );
}
/**
@@ -94,7 +94,7 @@ class Tests_Formatting_Date extends WP_UnitTestCase {
function test_get_gmt_from_date_string_date_no_timezone() {
$local = 'now';
$gmt = gmdate( 'Y-m-d H:i:s' );
- $this->assertEquals( strtotime( $gmt ), strtotime( get_gmt_from_date( $local ) ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( $gmt ), strtotime( get_gmt_from_date( $local ) ), 2, 'The dates should be equal' );
}
/**
diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php
index 9131ab2cdb..06b8cdb59a 100644
--- a/tests/phpunit/tests/media.php
+++ b/tests/phpunit/tests/media.php
@@ -440,16 +440,16 @@ https://w.org</a>',
// Now some values around.
$hr = wp_convert_bytes_to_hr( $tb + $tb / 2 + $mb );
- $this->assertEquals( 1.50000095367, (float) str_replace( ',', '.', $hr ), 'The values should be equal', 0.0001 );
+ $this->assertEqualsWithDelta( 1.50000095367, (float) str_replace( ',', '.', $hr ), 0.0001, 'The values should be equal' );
$hr = wp_convert_bytes_to_hr( $tb - $mb - $kb );
- $this->assertEquals( 1023.99902248, (float) str_replace( ',', '.', $hr ), 'The values should be equal', 0.0001 );
+ $this->assertEqualsWithDelta( 1023.99902248, (float) str_replace( ',', '.', $hr ), 0.0001, 'The values should be equal' );
$hr = wp_convert_bytes_to_hr( $gb + $gb / 2 + $mb );
- $this->assertEquals( 1.5009765625, (float) str_replace( ',', '.', $hr ), 'The values should be equal', 0.0001 );
+ $this->assertEqualsWithDelta( 1.5009765625, (float) str_replace( ',', '.', $hr ), 0.0001, 'The values should be equal' );
$hr = wp_convert_bytes_to_hr( $gb - $mb - $kb );
- $this->assertEquals( 1022.99902344, (float) str_replace( ',', '.', $hr ), 'The values should be equal', 0.0001 );
+ $this->assertEqualsWithDelta( 1022.99902344, (float) str_replace( ',', '.', $hr ), 0.0001, 'The values should be equal' );
// Edge.
$this->assertSame( '-1B', wp_convert_bytes_to_hr( -1 ) );
diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php
index a76e993436..567ad835d1 100644
--- a/tests/phpunit/tests/multisite/site.php
+++ b/tests/phpunit/tests/multisite/site.php
@@ -409,7 +409,7 @@ if ( is_multisite() ) :
$current_time = time();
// Compare the update time with the current time, allow delta < 2.
- $this->assertEquals( $current_time, strtotime( $blog->last_updated ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( $current_time, strtotime( $blog->last_updated ), 2, 'The dates should be equal' );
}
/**
@@ -1792,16 +1792,16 @@ if ( is_multisite() ) :
$this->assertInternalType( 'integer', $site_id );
$site = get_site( $site_id );
- $this->assertEquals( strtotime( $first_date ), strtotime( $site->registered ), 'The dates should be equal', 2 );
- $this->assertEquals( strtotime( $first_date ), strtotime( $site->last_updated ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( $first_date ), strtotime( $site->registered ), 2, 'The dates should be equal' );
+ $this->assertEqualsWithDelta( strtotime( $first_date ), strtotime( $site->last_updated ), 2, 'The dates should be equal' );
$second_date = current_time( 'mysql', true );
$site_id = wp_update_site( $site_id, array() );
$this->assertInternalType( 'integer', $site_id );
$site = get_site( $site_id );
- $this->assertEquals( strtotime( $first_date ), strtotime( $site->registered ), 'The dates should be equal', 2 );
- $this->assertEquals( strtotime( $second_date ), strtotime( $site->last_updated ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( $first_date ), strtotime( $site->registered ), 2, 'The dates should be equal' );
+ $this->assertEqualsWithDelta( strtotime( $second_date ), strtotime( $site->last_updated ), 2, 'The dates should be equal' );
}
/**
diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php
index 8c5cb0000f..bacf9b23c5 100644
--- a/tests/phpunit/tests/post.php
+++ b/tests/phpunit/tests/post.php
@@ -1352,7 +1352,7 @@ class Tests_Post extends WP_UnitTestCase {
);
$post = get_post( $post_id );
- self::assertEquals( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date_gmt ), 'The dates should be equal', 2 );
+ self::assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date_gmt ), 2, 'The dates should be equal' );
}
/**
diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php
index 1e84b14844..9831bb0aab 100644
--- a/tests/phpunit/tests/rest-api/rest-posts-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php
@@ -4639,8 +4639,8 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
$response = rest_get_server()->dispatch( $put );
$body = $response->get_data();
- $this->assertEquals( strtotime( $get_body['date'] ), strtotime( $body['date'] ), 'The dates should be equal', 2 );
- $this->assertEquals( strtotime( $get_body['date_gmt'] ), strtotime( $body['date_gmt'] ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( $get_body['date'] ), strtotime( $body['date'] ), 2, 'The dates should be equal' );
+ $this->assertEqualsWithDelta( strtotime( $get_body['date_gmt'] ), strtotime( $body['date_gmt'] ), 2, 'The dates should be equal' );
$this->assertSame( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt );
}
@@ -4682,7 +4682,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
$response = rest_get_server()->dispatch( $put );
$body = $response->get_data();
- $this->assertEquals( strtotime( mysql_to_rfc3339( $new_time ) ), strtotime( $body['date'] ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( mysql_to_rfc3339( $new_time ) ), strtotime( $body['date'] ), 2, 'The dates should be equal' );
$this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt );
}
@@ -4723,8 +4723,8 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
$response = rest_get_server()->dispatch( $put );
$body = $response->get_data();
- $this->assertEquals( strtotime( $get_body['date'] ), strtotime( $body['date'] ), 'The dates should be equal', 2 );
- $this->assertEquals( strtotime( $get_body['date_gmt'] ), strtotime( $body['date_gmt'] ), 'The dates should be equal', 2 );
+ $this->assertEqualsWithDelta( strtotime( $get_body['date'] ), strtotime( $body['date'] ), 2, 'The dates should be equal' );
+ $this->assertEqualsWithDelta( strtotime( $get_body['date_gmt'] ), strtotime( $body['date_gmt'] ), 2, 'The dates should be equal' );
$this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt );
}