[wp-trac] [WordPress Trac] #39327: Database connection errors in unit tests on 4.7

WordPress Trac noreply at wordpress.org
Mon Dec 19 05:52:22 UTC 2016


#39327: Database connection errors in unit tests on 4.7
------------------------------+------------------------------------
 Reporter:  rmccue            |      Owner:
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Future Release
Component:  Build/Test Tools  |    Version:  4.7
 Severity:  normal            |   Keywords:  needs-patch blame-gary
  Focuses:                    |
------------------------------+------------------------------------
 Between 4.6 and 4.7, wpdb ''somehow broke'', with "Couldn't fetch mysqli"
 being thrown.

 Tracked this down a bit with @pento; it turns out to be a problem with
 PHPUnit's global backups, and can be fixed by setting `protected
 $backupGlobals = true` in the test class. The key is that PHPUnit
 serialises the data and unserialises it to restore it. Adding this to wpdb
 also fixes it:

 {{{
 public function __wakeup() {
         $this->db_connect();
 }
 }}}

 As @pento mentioned, this is somewhat known behaviour; wpdb isn't designed
 to be serialized and unserialized. The question is not why this error
 occurs, but rather: what changed between 4.6 and 4.7?

 There were no relevant changes to wpdb, and running 4.6 with a 4.7-ified
 `wp-db.php` does not cause the error, so the error is somewhere else.

 Will try and track this down. I'm experiencing it, and it has been
 [https://wordpress.org/support/topic/wp_unittestcaseteardown-causes-
 mysqli_query-couldnt-fetch-mysqli/ independently reported on the forums
 too].

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39327>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list