Changeset 48952
- Timestamp:
- 09/07/2020 03:12:17 AM (4 years ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/phpunit6/compat.php
r46625 r48952 12 12 class_alias( 'PHPUnit\Framework\Warning', 'PHPUnit_Framework_Warning' ); 13 13 class_alias( 'PHPUnit\Framework\AssertionFailedError', 'PHPUnit_Framework_AssertionFailedError' ); 14 class_alias( 'PHPUnit\Framework\Constraint\IsEqual', 'PHPUnit_Framework_Constraint_IsEqual' ); 14 15 class_alias( 'PHPUnit\Framework\TestSuite', 'PHPUnit_Framework_TestSuite' ); 15 16 class_alias( 'PHPUnit\Framework\TestListener', 'PHPUnit_Framework_TestListener' ); -
trunk/tests/phpunit/includes/phpunit7/testcase.php
r47198 r48952 17 17 * Asserts that a condition is not false. 18 18 * 19 * This method has been backported from a more recent PHPUnit version, as tests running on PHP 5.2 use20 * PHPUnit 3.6.x.19 * This method has been backported from a more recent PHPUnit version, 20 * as tests running on PHP 5.2 use PHPUnit 3.6.x. 21 21 * 22 22 * @since 4.7.4 … … 30 30 self::assertThat( $condition, self::logicalNot( self::isFalse() ), $message ); 31 31 } 32 33 /** 34 * Asserts that two variables are equal (with delta). 35 * 36 * This method has been backported from a more recent PHPUnit version, 37 * as tests running on PHP 5.6 use PHPUnit 5.7.x. 38 * 39 * @since 5.6.0 40 * 41 * @param mixed $expected First value to compare. 42 * @param mixed $actual Second value to compare. 43 * @param float $delta Allowed numerical distance between two values to consider them equal. 44 * @param string $message Optional. Message to display when the assertion fails. 45 * 46 * @throws ExpectationFailedException 47 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException 48 */ 49 public static function assertEqualsWithDelta( $expected, $actual, float $delta, string $message = '' ): void { 50 $constraint = new PHPUnit\Framework\Constraint\IsEqual( 51 $expected, 52 $delta 53 ); 54 55 static::assertThat( $actual, $constraint, $message ); 56 } 32 57 } -
trunk/tests/phpunit/includes/testcase.php
r47198 r48952 17 17 * Asserts that a condition is not false. 18 18 * 19 * This method has been backported from a more recent PHPUnit version, as tests running on PHP 5.2 use20 * PHPUnit 3.6.x.19 * This method has been backported from a more recent PHPUnit version, 20 * as tests running on PHP 5.2 use PHPUnit 3.6.x. 21 21 * 22 22 * @since 4.7.4 … … 30 30 self::assertThat( $condition, self::logicalNot( self::isFalse() ), $message ); 31 31 } 32 33 /** 34 * Asserts that two variables are equal (with delta). 35 * 36 * This method has been backported from a more recent PHPUnit version, 37 * as tests running on PHP 5.6 use PHPUnit 5.7.x. 38 * 39 * @since 5.6.0 40 * 41 * @param mixed $expected First value to compare. 42 * @param mixed $actual Second value to compare. 43 * @param float $delta Allowed numerical distance between two values to consider them equal. 44 * @param string $message Optional. Message to display when the assertion fails. 45 * 46 * @throws ExpectationFailedException 47 * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException 48 */ 49 public static function assertEqualsWithDelta( $expected, $actual, $delta, $message = '' ) { 50 $constraint = new PHPUnit_Framework_Constraint_IsEqual( 51 $expected, 52 $delta 53 ); 54 55 static::assertThat( $actual, $constraint, $message ); 56 } 32 57 } -
trunk/tests/phpunit/tests/date/currentTime.php
r47118 r48952 17 17 $wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS; 18 18 19 $this->assertEquals ( strtotime( gmdate( $format ) ), strtotime( current_time( $format, true ) ), 'The dates should be equal', 2);20 $this->assertEquals ( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( $format ) ), 'The dates should be equal', 2);19 $this->assertEqualsWithDelta( strtotime( gmdate( $format ) ), strtotime( current_time( $format, true ) ), 2, 'The dates should be equal' ); 20 $this->assertEqualsWithDelta( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( $format ) ), 2, 'The dates should be equal' ); 21 21 } 22 22 … … 31 31 $wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS; 32 32 33 $this->assertEquals ( strtotime( gmdate( $format ) ), strtotime( current_time( 'mysql', true ) ), 'The dates should be equal', 2);34 $this->assertEquals ( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( 'mysql' ) ), 'The dates should be equal', 2);33 $this->assertEqualsWithDelta( strtotime( gmdate( $format ) ), strtotime( current_time( 'mysql', true ) ), 2, 'The dates should be equal' ); 34 $this->assertEqualsWithDelta( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( 'mysql' ) ), 2, 'The dates should be equal' ); 35 35 } 36 36 … … 45 45 46 46 // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC 47 $this->assertEquals ( $timestamp, current_time( 'timestamp', true ), 'The dates should be equal', 2);47 $this->assertEqualsWithDelta( $timestamp, current_time( 'timestamp', true ), 2, 'The dates should be equal' ); 48 48 // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested 49 $this->assertEquals ( $wp_timestamp, current_time( 'timestamp' ), 'The dates should be equal', 2);49 $this->assertEqualsWithDelta( $wp_timestamp, current_time( 'timestamp' ), 2, 'The dates should be equal' ); 50 50 } 51 51 … … 71 71 $current_time = current_time( $format ); 72 72 73 $this->assertEquals ( strtotime( gmdate( $format ) ), strtotime( $current_time_custom_timezone_gmt ), 'The dates should be equal', 2);74 $this->assertEquals ( strtotime( $datetime->format( $format ) ), strtotime( $current_time_custom_timezone ), 'The dates should be equal', 2);75 $this->assertEquals ( strtotime( gmdate( $format ) ), strtotime( $current_time_gmt ), 'The dates should be equal', 2);76 $this->assertEquals ( strtotime( $datetime->format( $format ) ), strtotime( $current_time ), 'The dates should be equal', 2);73 $this->assertEqualsWithDelta( strtotime( gmdate( $format ) ), strtotime( $current_time_custom_timezone_gmt ), 2, 'The dates should be equal' ); 74 $this->assertEqualsWithDelta( strtotime( $datetime->format( $format ) ), strtotime( $current_time_custom_timezone ), 2, 'The dates should be equal' ); 75 $this->assertEqualsWithDelta( strtotime( gmdate( $format ) ), strtotime( $current_time_gmt ), 2, 'The dates should be equal' ); 76 $this->assertEqualsWithDelta( strtotime( $datetime->format( $format ) ), strtotime( $current_time ), 2, 'The dates should be equal' ); 77 77 } 78 78 … … 89 89 90 90 // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC 91 $this->assertEquals ( $timestamp, current_time( 'timestamp', true ), 'The dates should be equal', 2);91 $this->assertEqualsWithDelta( $timestamp, current_time( 'timestamp', true ), 2, 'The dates should be equal' ); 92 92 // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC 93 $this->assertEquals ( $timestamp, current_time( 'U', true ), 'The dates should be equal', 2);93 $this->assertEqualsWithDelta( $timestamp, current_time( 'U', true ), 2, 'The dates should be equal' ); 94 94 95 95 // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested 96 $this->assertEquals ( $wp_timestamp, current_time( 'timestamp' ), 'The dates should be equal', 2);96 $this->assertEqualsWithDelta( $wp_timestamp, current_time( 'timestamp' ), 2, 'The dates should be equal' ); 97 97 // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested 98 $this->assertEquals ( $wp_timestamp, current_time( 'U' ), 'The dates should be equal', 2);98 $this->assertEqualsWithDelta( $wp_timestamp, current_time( 'U' ), 2, 'The dates should be equal' ); 99 99 100 100 // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested … … 114 114 $datetime_utc->setTimezone( new DateTimeZone( 'UTC' ) ); 115 115 116 $this->assertEquals ( strtotime( $datetime_local->format( DATE_W3C ) ), strtotime( current_time( DATE_W3C ) ), 'The dates should be equal', 2);117 $this->assertEquals ( strtotime( $datetime_utc->format( DATE_W3C ) ), strtotime( current_time( DATE_W3C, true ) ), 'The dates should be equal', 2);116 $this->assertEqualsWithDelta( strtotime( $datetime_local->format( DATE_W3C ) ), strtotime( current_time( DATE_W3C ) ), 2, 'The dates should be equal' ); 117 $this->assertEqualsWithDelta( strtotime( $datetime_utc->format( DATE_W3C ) ), strtotime( current_time( DATE_W3C, true ) ), 2, 'The dates should be equal' ); 118 118 } 119 119 } -
trunk/tests/phpunit/tests/date/dateI18n.php
r48937 r48952 17 17 $wp_timestamp = $datetime->getTimestamp() + $datetime->getOffset(); 18 18 19 $this->assertEquals ( $wp_timestamp, date_i18n( 'U', 'invalid' ), '', 5);19 $this->assertEqualsWithDelta( $wp_timestamp, date_i18n( 'U', 'invalid' ), 5, 'The dates should be equal' ); 20 20 } 21 21 … … 39 39 40 40 public function test_should_format_date() { 41 $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);41 $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' ); 42 42 } 43 43 … … 47 47 48 48 public function test_date_should_be_in_gmt() { 49 $this->assertEquals ( strtotime( gmdate( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 'The dates should be equal', 2);49 $this->assertEqualsWithDelta( strtotime( gmdate( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 2, 'The dates should be equal' ); 50 50 } 51 51 … … 53 53 update_option( 'timezone_string', 'America/Regina' ); 54 54 55 $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);55 $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' ); 56 56 } 57 57 … … 59 59 update_option( 'timezone_string', 'America/Regina' ); 60 60 61 $this->assertEquals ( strtotime( gmdate( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 'The dates should be equal', 2);61 $this->assertEqualsWithDelta( strtotime( gmdate( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 2, 'The dates should be equal' ); 62 62 } 63 63 … … 122 122 update_option( 'timezone_string', 'America/Regina' ); 123 123 124 $this->assertEquals ( strtotime( date_i18n( $full ) ), strtotime( date_i18n( $short ) ), 'The dates should be equal', 2);124 $this->assertEqualsWithDelta( strtotime( date_i18n( $full ) ), strtotime( date_i18n( $short ) ), 2, 'The dates should be equal' ); 125 125 $this->assertSame( $short, date_i18n( '\\' . $short ) ); 126 126 } … … 149 149 $wp_timestamp = $timestamp + $datetime->getOffset(); 150 150 151 $this->assertEquals ( $wp_timestamp, date_i18n( 'U' ), 'The dates should be equal', 2);152 $this->assertEquals ( $timestamp, date_i18n( 'U', false, true ), 'The dates should be equal', 2);151 $this->assertEqualsWithDelta( $wp_timestamp, date_i18n( 'U' ), 2, 'The dates should be equal' ); 152 $this->assertEqualsWithDelta( $timestamp, date_i18n( 'U', false, true ), 2, 'The dates should be equal' ); 153 153 $this->assertSame( $wp_timestamp, date_i18n( 'U', $wp_timestamp ) ); 154 154 } -
trunk/tests/phpunit/tests/date/getFeedBuildDate.php
r48937 r48952 61 61 ); 62 62 63 $this->assertEquals (63 $this->assertEqualsWithDelta( 64 64 strtotime( $datetime_utc->format( DATE_RFC3339 ) ), 65 65 strtotime( get_feed_build_date( DATE_RFC3339 ) ), 66 'Fall back to time of last post modified with no posts',67 266 2, 67 'Fall back to time of last post modified with no posts' 68 68 ); 69 69 … … 75 75 $wp_query->posts = array( $post_broken ); 76 76 77 $this->assertEquals (77 $this->assertEqualsWithDelta( 78 78 strtotime( $datetime_utc->format( DATE_RFC3339 ) ), 79 79 strtotime( get_feed_build_date( DATE_RFC3339 ) ), 80 'Fall back to time of last post modified with broken post object',81 280 2, 81 'Fall back to time of last post modified with broken post object' 82 82 ); 83 83 } -
trunk/tests/phpunit/tests/date/query.php
r48937 r48952 525 525 526 526 $message = "Expected {$expected}, got {$found}"; 527 $this->assertEquals ( strtotime( $expected ), strtotime( $found ), $message, 10);527 $this->assertEqualsWithDelta( strtotime( $expected ), strtotime( $found ), 10, $message ); 528 528 } 529 529 … … 560 560 561 561 $message = "Expected {$expected}, got {$found}"; 562 $this->assertEquals ( strtotime( $expected ), strtotime( $found ), $message, 10);562 $this->assertEqualsWithDelta( strtotime( $expected ), strtotime( $found ), 10, $message ); 563 563 564 564 } … … 584 584 585 585 $message = "Expected {$expected}, got {$found}"; 586 $this->assertEquals ( strtotime( $expected ), strtotime( $found ), $message, 10);586 $this->assertEqualsWithDelta( strtotime( $expected ), strtotime( $found ), 10, $message ); 587 587 } 588 588 -
trunk/tests/phpunit/tests/formatting/date.php
r48937 r48952 86 86 $local = 'now'; 87 87 $gmt = gmdate( 'Y-m-d H:i:s' ); 88 $this->assertEquals ( strtotime( $gmt ), strtotime( get_gmt_from_date( $local ) ), 'The dates should be equal', 2);88 $this->assertEqualsWithDelta( strtotime( $gmt ), strtotime( get_gmt_from_date( $local ) ), 2, 'The dates should be equal' ); 89 89 } 90 90 … … 95 95 $local = 'now'; 96 96 $gmt = gmdate( 'Y-m-d H:i:s' ); 97 $this->assertEquals ( strtotime( $gmt ), strtotime( get_gmt_from_date( $local ) ), 'The dates should be equal', 2);97 $this->assertEqualsWithDelta( strtotime( $gmt ), strtotime( get_gmt_from_date( $local ) ), 2, 'The dates should be equal' ); 98 98 } 99 99 -
trunk/tests/phpunit/tests/media.php
r48937 r48952 441 441 // Now some values around. 442 442 $hr = wp_convert_bytes_to_hr( $tb + $tb / 2 + $mb ); 443 $this->assertEquals ( 1.50000095367, (float) str_replace( ',', '.', $hr ), 'The values should be equal', 0.0001);443 $this->assertEqualsWithDelta( 1.50000095367, (float) str_replace( ',', '.', $hr ), 0.0001, 'The values should be equal' ); 444 444 445 445 $hr = wp_convert_bytes_to_hr( $tb - $mb - $kb ); 446 $this->assertEquals ( 1023.99902248, (float) str_replace( ',', '.', $hr ), 'The values should be equal', 0.0001);446 $this->assertEqualsWithDelta( 1023.99902248, (float) str_replace( ',', '.', $hr ), 0.0001, 'The values should be equal' ); 447 447 448 448 $hr = wp_convert_bytes_to_hr( $gb + $gb / 2 + $mb ); 449 $this->assertEquals ( 1.5009765625, (float) str_replace( ',', '.', $hr ), 'The values should be equal', 0.0001);449 $this->assertEqualsWithDelta( 1.5009765625, (float) str_replace( ',', '.', $hr ), 0.0001, 'The values should be equal' ); 450 450 451 451 $hr = wp_convert_bytes_to_hr( $gb - $mb - $kb ); 452 $this->assertEquals ( 1022.99902344, (float) str_replace( ',', '.', $hr ), 'The values should be equal', 0.0001);452 $this->assertEqualsWithDelta( 1022.99902344, (float) str_replace( ',', '.', $hr ), 0.0001, 'The values should be equal' ); 453 453 454 454 // Edge. -
trunk/tests/phpunit/tests/multisite/site.php
r48939 r48952 410 410 411 411 // Compare the update time with the current time, allow delta < 2. 412 $this->assertEquals ( $current_time, strtotime( $blog->last_updated ), 'The dates should be equal', 2);412 $this->assertEqualsWithDelta( $current_time, strtotime( $blog->last_updated ), 2, 'The dates should be equal' ); 413 413 } 414 414 … … 1793 1793 1794 1794 $site = get_site( $site_id ); 1795 $this->assertEquals ( strtotime( $first_date ), strtotime( $site->registered ), 'The dates should be equal', 2);1796 $this->assertEquals ( strtotime( $first_date ), strtotime( $site->last_updated ), 'The dates should be equal', 2);1795 $this->assertEqualsWithDelta( strtotime( $first_date ), strtotime( $site->registered ), 2, 'The dates should be equal' ); 1796 $this->assertEqualsWithDelta( strtotime( $first_date ), strtotime( $site->last_updated ), 2, 'The dates should be equal' ); 1797 1797 1798 1798 $second_date = current_time( 'mysql', true ); … … 1801 1801 1802 1802 $site = get_site( $site_id ); 1803 $this->assertEquals ( strtotime( $first_date ), strtotime( $site->registered ), 'The dates should be equal', 2);1804 $this->assertEquals ( strtotime( $second_date ), strtotime( $site->last_updated ), 'The dates should be equal', 2);1803 $this->assertEqualsWithDelta( strtotime( $first_date ), strtotime( $site->registered ), 2, 'The dates should be equal' ); 1804 $this->assertEqualsWithDelta( strtotime( $second_date ), strtotime( $site->last_updated ), 2, 'The dates should be equal' ); 1805 1805 } 1806 1806 -
trunk/tests/phpunit/tests/post.php
r48939 r48952 1353 1353 1354 1354 $post = get_post( $post_id ); 1355 self::assertEquals ( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date_gmt ), 'The dates should be equal', 2);1355 self::assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date_gmt ), 2, 'The dates should be equal' ); 1356 1356 } 1357 1357 -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r48939 r48952 4640 4640 $body = $response->get_data(); 4641 4641 4642 $this->assertEquals ( strtotime( $get_body['date'] ), strtotime( $body['date'] ), 'The dates should be equal', 2);4643 $this->assertEquals ( strtotime( $get_body['date_gmt'] ), strtotime( $body['date_gmt'] ), 'The dates should be equal', 2);4642 $this->assertEqualsWithDelta( strtotime( $get_body['date'] ), strtotime( $body['date'] ), 2, 'The dates should be equal' ); 4643 $this->assertEqualsWithDelta( strtotime( $get_body['date_gmt'] ), strtotime( $body['date_gmt'] ), 2, 'The dates should be equal' ); 4644 4644 4645 4645 $this->assertSame( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); … … 4683 4683 $body = $response->get_data(); 4684 4684 4685 $this->assertEquals ( strtotime( mysql_to_rfc3339( $new_time ) ), strtotime( $body['date'] ), 'The dates should be equal', 2);4685 $this->assertEqualsWithDelta( strtotime( mysql_to_rfc3339( $new_time ) ), strtotime( $body['date'] ), 2, 'The dates should be equal' ); 4686 4686 4687 4687 $this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); … … 4724 4724 $body = $response->get_data(); 4725 4725 4726 $this->assertEquals ( strtotime( $get_body['date'] ), strtotime( $body['date'] ), 'The dates should be equal', 2);4727 $this->assertEquals ( strtotime( $get_body['date_gmt'] ), strtotime( $body['date_gmt'] ), 'The dates should be equal', 2);4726 $this->assertEqualsWithDelta( strtotime( $get_body['date'] ), strtotime( $body['date'] ), 2, 'The dates should be equal' ); 4727 $this->assertEqualsWithDelta( strtotime( $get_body['date_gmt'] ), strtotime( $body['date_gmt'] ), 2, 'The dates should be equal' ); 4728 4728 4729 4729 $this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt );
Note: See TracChangeset
for help on using the changeset viewer.