Make WordPress Core


Ignore:
Timestamp:
03/15/2019 10:13:30 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Minor code and performance improvements in phpunit/includes/abstract-testcase.php.

Props andizer.
Fixes #46500.

File:
1 edited

Legend:

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

    r44904 r44916  
    388388     */
    389389    public function _create_temporary_tables( $query ) {
    390         if ( 'CREATE TABLE' === substr( trim( $query ), 0, 12 ) ) {
     390        if ( 0 === strpos( trim( $query ), 'CREATE TABLE' ) ) {
    391391            return substr_replace( trim( $query ), 'CREATE TEMPORARY TABLE', 0, 12 );
    392392        }
     
    401401     */
    402402    public function _drop_temporary_tables( $query ) {
    403         if ( 'DROP TABLE' === substr( trim( $query ), 0, 10 ) ) {
     403        if ( 0 === strpos( trim( $query ), 'DROP TABLE' ) ) {
    404404            return substr_replace( trim( $query ), 'DROP TEMPORARY TABLE', 0, 10 );
    405405        }
     
    512512     */
    513513    public function setExpectedDeprecated( $deprecated ) {
    514         array_push( $this->expected_deprecated, $deprecated );
     514        $this->expected_deprecated[] = $deprecated;
    515515    }
    516516
     
    524524     */
    525525    public function setExpectedIncorrectUsage( $doing_it_wrong ) {
    526         array_push( $this->expected_doing_it_wrong, $doing_it_wrong );
     526        $this->expected_doing_it_wrong[] = $doing_it_wrong;
    527527    }
    528528
     
    554554     */
    555555    public function deprecated_function_run( $function ) {
    556         if ( ! in_array( $function, $this->caught_deprecated ) ) {
     556        if ( ! in_array( $function, $this->caught_deprecated, true ) ) {
    557557            $this->caught_deprecated[] = $function;
    558558        }
     
    565565     */
    566566    public function doing_it_wrong_run( $function ) {
    567         if ( ! in_array( $function, $this->caught_doing_it_wrong ) ) {
     567        if ( ! in_array( $function, $this->caught_doing_it_wrong, true ) ) {
    568568            $this->caught_doing_it_wrong[] = $function;
    569569        }
     
    587587     */
    588588    public function assertNotWPError( $actual, $message = '' ) {
    589         if ( is_wp_error( $actual ) && '' === $message ) {
     589        if ( '' === $message && is_wp_error( $actual ) ) {
    590590            $message = $actual->get_error_message();
    591591        }
     
    625625    public function assertEqualFields( $object, $fields ) {
    626626        foreach ( $fields as $field_name => $field_value ) {
    627             if ( $object->$field_name != $field_value ) {
     627            if ( $object->$field_name !== $field_value ) {
    628628                $this->fail();
    629629            }
     
    789789            if ( is_numeric( $ticket ) ) {
    790790                $this->knownWPBug( $ticket );
    791             } elseif ( 'Plugin' == substr( $ticket, 0, 6 ) ) {
     791            } elseif ( 0 === strpos( $ticket, 'Plugin' ) ) {
    792792                $ticket = substr( $ticket, 6 );
    793793                if ( $ticket && is_numeric( $ticket ) ) {
     
    806806     */
    807807    public function knownWPBug( $ticket_id ) {
    808         if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( $ticket_id, self::$forced_tickets ) ) {
     808        if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( $ticket_id, self::$forced_tickets, true ) ) {
    809809            return;
    810810        }
     
    835835     */
    836836    public function knownPluginBug( $ticket_id ) {
    837         if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'Plugin' . $ticket_id, self::$forced_tickets ) ) {
     837        if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'Plugin' . $ticket_id, self::$forced_tickets, true ) ) {
    838838            return;
    839839        }
     
    951951            $result = is_callable( $query_thing ) ? call_user_func( $query_thing ) : $wp_query->$query_thing;
    952952
    953             if ( in_array( $query_thing, $true ) ) {
     953            if ( in_array( $query_thing, $true, true ) ) {
    954954                if ( ! $result ) {
    955955                    $message .= $query_thing . ' is false but is expected to be true. ' . PHP_EOL;
     
    976976    public function unlink( $file ) {
    977977        $exists = is_file( $file );
    978         if ( $exists && ! in_array( $file, self::$ignore_files ) ) {
     978        if ( $exists && ! in_array( $file, self::$ignore_files, true ) ) {
    979979            //error_log( $file );
    980980            unlink( $file );
     
    994994        $files = $this->files_in_dir( $path );
    995995        foreach ( $files as $file ) {
    996             if ( ! in_array( $file, self::$ignore_files ) ) {
     996            if ( ! in_array( $file, self::$ignore_files, true ) ) {
    997997                $this->unlink( $file );
    998998            }
     
    11171117        if ( is_multisite() ) {
    11181118            return wpmu_delete_user( $user_id );
    1119         } else {
    1120             return wp_delete_user( $user_id );
    1121         }
     1119        }
     1120
     1121        return wp_delete_user( $user_id );
    11221122    }
    11231123
Note: See TracChangeset for help on using the changeset viewer.