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
This commit is contained in:
Sergey Biryukov 2021-07-22 17:39:03 +00:00
parent dc568b181b
commit d8c3bc78a1

View File

@ -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.' );
}
}