From 043d3b54a853b796490a1af5fbff0e8d1a10e5b7 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 11 Apr 2017 10:48:00 +0000 Subject: [PATCH] Build/Test tools: Improve the failure message reported by `assertQueryTrue()` so it's a little less cryptic. Fixes #40411 git-svn-id: https://develop.svn.wordpress.org/trunk@40416 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/testcase.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index c77511d3a4..8e845db704 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -627,7 +627,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { /** * Check each of the WP_Query is_* functions/properties against expected boolean value. * - * Any properties that are listed by name as parameters will be expected to be true; any others are + * Any properties that are listed by name as parameters will be expected to be true; all others are * expected to be false. For example, assertQueryTrue('is_single', 'is_feed') means is_single() * and is_feed() must be true and everything else must be false to pass. * @@ -668,32 +668,29 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { $true = func_get_args(); foreach ( $true as $true_thing ) { - $this->assertContains( $true_thing, $all, "{$true_thing}() is not handled by assertQueryTrue()." ); + $this->assertContains( $true_thing, $all, "Unknown conditional: {$true_thing}." ); } $passed = true; - $not_false = $not_true = array(); // properties that were not set to expected values + $message = ''; foreach ( $all as $query_thing ) { $result = is_callable( $query_thing ) ? call_user_func( $query_thing ) : $wp_query->$query_thing; if ( in_array( $query_thing, $true ) ) { if ( ! $result ) { - array_push( $not_true, $query_thing ); + $message .= $query_thing . ' is false but is expected to be true. ' . PHP_EOL; $passed = false; } } else if ( $result ) { - array_push( $not_false, $query_thing ); + $message .= $query_thing . ' is true but is expected to be false. ' . PHP_EOL; $passed = false; } } - $message = ''; - if ( count($not_true) ) - $message .= implode( $not_true, ', ' ) . ' is expected to be true. '; - if ( count($not_false) ) - $message .= implode( $not_false, ', ' ) . ' is expected to be false.'; - $this->assertTrue( $passed, $message ); + if ( ! $passed ) { + $this->fail( $message ); + } } function unlink( $file ) {