WordPress.org

Make WordPress Core

Changeset 40416


Ignore:
Timestamp:
04/11/2017 10:48:00 AM (14 months ago)
Author:
johnbillion
Message:

Build/Test tools: Improve the failure message reported by assertQueryTrue() so it's a little less cryptic.

Fixes #40411

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r40347 r40416  
    628628     * Check each of the WP_Query is_* functions/properties against expected boolean value.
    629629     *
    630      * Any properties that are listed by name as parameters will be expected to be true; any others are
     630     * Any properties that are listed by name as parameters will be expected to be true; all others are
    631631     * expected to be false. For example, assertQueryTrue('is_single', 'is_feed') means is_single()
    632632     * and is_feed() must be true and everything else must be false to pass.
     
    669669
    670670        foreach ( $true as $true_thing ) {
    671             $this->assertContains( $true_thing, $all, "{$true_thing}() is not handled by assertQueryTrue()." );
     671            $this->assertContains( $true_thing, $all, "Unknown conditional: {$true_thing}." );
    672672        }
    673673
    674674        $passed = true;
    675         $not_false = $not_true = array(); // properties that were not set to expected values
     675        $message = '';
    676676
    677677        foreach ( $all as $query_thing ) {
     
    680680            if ( in_array( $query_thing, $true ) ) {
    681681                if ( ! $result ) {
    682                     array_push( $not_true, $query_thing );
     682                    $message .= $query_thing . ' is false but is expected to be true. ' . PHP_EOL;
    683683                    $passed = false;
    684684                }
    685685            } else if ( $result ) {
    686                 array_push( $not_false, $query_thing );
     686                $message .= $query_thing . ' is true but is expected to be false. ' . PHP_EOL;
    687687                $passed = false;
    688688            }
    689689        }
    690690
    691         $message = '';
    692         if ( count($not_true) )
    693             $message .= implode( $not_true, ', ' ) . ' is expected to be true. ';
    694         if ( count($not_false) )
    695             $message .= implode( $not_false, ', ' ) . ' is expected to be false.';
    696         $this->assertTrue( $passed, $message );
     691        if ( ! $passed ) {
     692            $this->fail( $message );
     693        }
    697694    }
    698695
Note: See TracChangeset for help on using the changeset viewer.