Skip to content

Commit

Permalink
Used test_add_filter instead to load the code properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
zinigor committed Jun 11, 2024
1 parent c5b68f4 commit 75cb6be
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions projects/plugins/jetpack/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,32 +107,6 @@ function _manually_load_plugin() {
require JETPACK_WOOCOMMERCE_INSTALL_DIR . '/woocommerce.php';
}

if ( '1' === getenv( 'JETPACK_TEST_WPCOMSH' ) ) {
define( 'IS_ATOMIC', true );
if ( getenv( 'GITHUB_ACTIONS' ) ) {

// Using plugin code installed by .github/files/setup-wordpress-env.sh.
require_once __DIR__ . '/../../../../mu-plugins/wpcomsh/wpcomsh.php';
require_once __DIR__ . '/../../../../mu-plugins/wpcomsh/vendor/autoload.php';
} else {
require_once __DIR__ . '/../../../wpcomsh/wpcomsh.php';
require_once __DIR__ . '/../../../wpcomsh/vendor/autoload.php';
}
\Automattic\Jetpack\Jetpack_Mu_Wpcom::init();

// We can't simulate plugins_loaded because it causes a loop, but we can call load methods.
$reflection = new ReflectionClass( '\Automattic\Jetpack\Jetpack_Mu_Wpcom' );
foreach ( $reflection->getMethods() as $method ) {

// Verbum comments calls code that's not available in single site environment.
if ( str_starts_with( $method->name, 'load_' ) ) {
if ( 'load_verbum_comments' === $method->name ) {
continue;
}
$method->invoke( null );
}
}
}
require __DIR__ . '/../../jetpack.php';
$jetpack = Jetpack::init();
$jetpack->configure();
Expand All @@ -152,9 +126,36 @@ function _manually_install_woocommerce() {
echo 'Installing WooCommerce...' . PHP_EOL;
}

/**
* Loading required mu-wpcom plugin files to be able to test with all required code.
*/
function _manually_load_muplugin() {
if ( getenv( 'GITHUB_ACTIONS' ) ) {

// Using plugin code installed by .github/files/setup-wordpress-env.sh.
require_once __DIR__ . '/../../../../mu-plugins/wpcomsh/wpcomsh.php';
require_once __DIR__ . '/../../../../mu-plugins/wpcomsh/vendor/autoload.php';
} else {
require_once __DIR__ . '/../../../wpcomsh/wpcomsh.php';
require_once __DIR__ . '/../../../wpcomsh/vendor/autoload.php';
}
\Automattic\Jetpack\Jetpack_Mu_Wpcom::init();

Check failure on line 142 in projects/plugins/jetpack/tests/php/bootstrap.php

View workflow job for this annotation

GitHub Actions / Static analysis

UndefError PhanUndeclaredClassMethod Call to method init from undeclared class \Automattic\Jetpack\Jetpack_Mu_Wpcom

defined( 'WPCOMSH_PREMIUM_THEMES_PATH' ) || define( 'WPCOMSH_PREMIUM_THEMES_PATH', sys_get_temp_dir() . '/premium' );
if ( ! is_dir( WPCOMSH_PREMIUM_THEMES_PATH ) ) {
mkdir( WPCOMSH_PREMIUM_THEMES_PATH, 0777 );
}
}

// If we are running the uninstall tests don't load jetpack.
if ( ! ( in_running_uninstall_group() ) ) {
tests_add_filter( 'plugins_loaded', '_manually_load_plugin', 1 );

if ( '1' === getenv( 'JETPACK_TEST_WPCOMSH' ) ) {
define( 'IS_ATOMIC', true );
tests_add_filter( 'muplugins_loaded', '_manually_load_muplugin' );
}

if ( '1' === getenv( 'JETPACK_TEST_WOOCOMMERCE' ) ) {
tests_add_filter( 'setup_theme', '_manually_install_woocommerce' );
}
Expand Down

0 comments on commit 75cb6be

Please sign in to comment.