Make WordPress Core

Changeset 39626


Ignore:
Timestamp:
12/21/2016 04:58:47 AM (8 years ago)
Author:
pento
Message:

Tests: Restore the database connection earlier when switching test groups.

When plugins don't disable the backupGlobals PHPUnit option in their own tests, $wpdb is backed up and restored between classes of tests. The serialisation process used for this broke the database connection. This previously wasn't a problem, as it was reconnecting before each test.

[38398] introduced some changes that required the connection to be available in setUpBeforeClass(), earlier than in was previously reconnecting. This didn't cause warnings in Core, but it did cause warnings for plugins that don't disable the backupGlobals option.

The database connection now reconnects in setUpBeforeClass(). This change also fixes a few Core tests that weren't calling parent::setUpBeforeClass() or parent::tearDown() correctly.

Fixes #39327.

Location:
trunk/tests/phpunit
Files:
5 edited

Legend:

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

    r38678 r39626  
    5858
    5959    public static function setUpBeforeClass() {
     60        global $wpdb;
     61
     62        $wpdb->suppress_errors = false;
     63        $wpdb->show_errors = true;
     64        $wpdb->db_connect();
     65        ini_set('display_errors', 1 );
     66
    6067        parent::setUpBeforeClass();
    6168
     
    99106        }
    100107
    101         global $wpdb, $wp_rewrite;
    102         $wpdb->suppress_errors = false;
    103         $wpdb->show_errors = true;
    104         $wpdb->db_connect();
    105         ini_set('display_errors', 1 );
     108        global $wp_rewrite;
     109
    106110        $this->clean_up_global_scope();
    107111
  • trunk/tests/phpunit/includes/utils.php

    r38832 r39626  
    390390        $this->field_types = $wpdb->field_types;
    391391        $this->charset = $wpdb->charset;
     392
     393        $this->dbuser = $wpdb->dbuser;
     394        $this->dbpassword = $wpdb->dbpassword;
     395        $this->dbname = $wpdb->dbname;
     396        $this->dbhost = $wpdb->dbhost;
    392397    }
    393398
  • trunk/tests/phpunit/tests/db.php

    r39275 r39626  
    2121
    2222    public static function setUpBeforeClass() {
     23        parent::setUpBeforeClass();
    2324        self::$_wpdb = new wpdb_exposed_methods_for_testing();
    2425    }
     
    6465
    6566        $var = $wpdb->get_var( "SELECT ID FROM $wpdb->users LIMIT 1" );
     67
     68        // Ensure all database handles have been properly reconnected after this test.
     69        $wpdb->db_connect();
     70        self::$_wpdb->db_connect();
     71
    6672        $this->assertGreaterThan( 0, $var );
    6773    }
  • trunk/tests/phpunit/tests/db/charset.php

    r38843 r39626  
    2323
    2424    public static function setUpBeforeClass() {
     25        parent::setUpBeforeClass();
     26
    2527        require_once( dirname( dirname( __FILE__ ) ) . '/db.php' );
    2628
  • trunk/tests/phpunit/tests/rewrite/numericSlugs.php

    r36717 r39626  
    1717
    1818    public function tearDown() {
     19        parent::tearDown();
    1920        remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ), 10, 6 );
    2021    }
Note: See TracChangeset for help on using the changeset viewer.