From d8c3bc78a169e3471e461be6c9c1dc56b58ef256 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 22 Jul 2021 17:39:03 +0000 Subject: [PATCH] Tests: Modernize the `WP_UnitTestCase_Base::assertEqualFields()` method: * Use `assertSame()` instead of `fail()` to display a proper message in case of failure. * Add an optional `$message` parameter for consistency with other assertions. Follow-up to [51478], [51479]. See #53363. git-svn-id: https://develop.svn.wordpress.org/trunk@51480 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/abstract-testcase.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index b33991af64..115c741fe0 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -655,14 +655,16 @@ abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase { /** * Asserts that the given fields are present in the given object. * - * @param object $object The object to check. - * @param array $fields The fields to check. + * @since UT (3.7.0) + * @since 5.9.0 Added the `$message` parameter. + * + * @param object $object The object to check. + * @param array $fields The fields to check. + * @param string $message Optional. Message to display when the assertion fails. */ - public function assertEqualFields( $object, $fields ) { + public function assertEqualFields( $object, $fields, $message = '' ) { foreach ( $fields as $field_name => $field_value ) { - if ( $object->$field_name !== $field_value ) { - $this->fail(); - } + $this->assertSame( $object->$field_name, $field_value, $message . ' Field values do not match.' ); } }