WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/21/2016 05:07:05 AM (3 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.

Merges [39626] to the 4.7 branch.

Fixes #39327.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/tests/phpunit/includes/testcase.php

    r38678 r39627  
    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
Note: See TracChangeset for help on using the changeset viewer.