Skip to content

Commit

Permalink
Merge pull request #723 from lucatume/fix-issue-720
Browse files Browse the repository at this point in the history
Fix issue #720
  • Loading branch information
lucatume authored May 18, 2024
2 parents 6eaaa7c + e7fd809 commit 628c780
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

## Fixed

- Avoid calling `wpdb::db_connect()` twice during `WPLoader` bootstrap. (thanks @calvinalkan)

## [4.1.8] 2024-05-13;

### Changed
Expand Down
21 changes: 14 additions & 7 deletions config/patches/core-phpunit/includes/abstract-testcase.php.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/includes/core-phpunit/includes/abstract-testcase.php b/includes/core-phpunit/includes/abstract-testcase.php
index 3600722f..67c4d71c 100644
index f2978644..e092beca 100644
--- a/includes/core-phpunit/includes/abstract-testcase.php
+++ b/includes/core-phpunit/includes/abstract-testcase.php
@@ -20,6 +20,8 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase {
Expand Down Expand Up @@ -29,16 +29,23 @@ index 3600722f..67c4d71c 100644
}

/**
@@ -69,7 +71,7 @@ public static function set_up_before_class() {
$wpdb->db_connect();
ini_set( 'display_errors', 1 );
@@ -66,10 +68,12 @@ public static function set_up_before_class() {

$wpdb->suppress_errors = false;
$wpdb->show_errors = true;
- $wpdb->db_connect();
- ini_set( 'display_errors', 1 );
+ if ( ! $wpdb->check_connection() ) {
+ $wpdb->db_connect();
+ }
+ ini_set( 'display_errors', 1 );

- $class = get_called_class();
+ $class = self::$calledClass ?? get_called_class();

if ( method_exists( $class, 'wpSetUpBeforeClass' ) ) {
call_user_func( array( $class, 'wpSetUpBeforeClass' ), static::factory() );
@@ -82,7 +84,7 @@ public static function set_up_before_class() {
@@ -82,7 +86,7 @@ public static function set_up_before_class() {
* Runs the routine after all tests have been run.
*/
public static function tear_down_after_class() {
Expand All @@ -47,7 +54,7 @@ index 3600722f..67c4d71c 100644

if ( method_exists( $class, 'wpTearDownAfterClass' ) ) {
call_user_func( array( $class, 'wpTearDownAfterClass' ) );
@@ -646,7 +648,7 @@ public function expectedDeprecated() {
@@ -651,7 +655,7 @@ public function expectedDeprecated() {
*
* @since 4.2.0
*/
Expand All @@ -56,7 +63,7 @@ index 3600722f..67c4d71c 100644
$this->expectedDeprecated();
}

@@ -1655,4 +1657,9 @@ public static function touch( $file ) {
@@ -1660,4 +1664,9 @@ public static function touch( $file ) {

touch( $file );
}
Expand Down
6 changes: 4 additions & 2 deletions includes/core-phpunit/includes/abstract-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ public static function set_up_before_class() {

$wpdb->suppress_errors = false;
$wpdb->show_errors = true;
$wpdb->db_connect();
ini_set( 'display_errors', 1 );
if ( ! $wpdb->check_connection() ) {
$wpdb->db_connect();
}
ini_set( 'display_errors', 1 );

$class = self::$calledClass ?? get_called_class();

Expand Down

0 comments on commit 628c780

Please sign in to comment.