Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #720 #723

Merged
merged 2 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading