Skip to content

Commit

Permalink
Loading mu-wpcom features in the phpunit bootstrap.
Browse files Browse the repository at this point in the history
  • Loading branch information
zinigor committed Jun 11, 2024
1 parent 2b8cfc2 commit c5b68f4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
29 changes: 28 additions & 1 deletion projects/plugins/jetpack/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
echo "Disregard Core's -c tests/phpunit/multisite.xml notice below." . PHP_EOL;
}

if ( '1' !== getenv( 'JETPACK_TEST_WPCOMSH' ) ) {
echo 'To run tests with the WordPress.com Site Helper plugin activated and Atomic mode enabled,' . PHP_EOL;
echo 'prefix phpunit with JETPACK_TEST_WPCOMSH=1' . PHP_EOL;
}

if ( '1' !== getenv( 'JETPACK_TEST_WOOCOMMERCE' ) ) {
echo 'To run Jetpack woocommerce tests, prefix phpunit with JETPACK_TEST_WOOCOMMERCE=1' . PHP_EOL;
} else {
Expand All @@ -104,7 +109,29 @@ function _manually_load_plugin() {

if ( '1' === getenv( 'JETPACK_TEST_WPCOMSH' ) ) {
define( 'IS_ATOMIC', true );
require __DIR__ . '/../../../../mu-plugins/wpcomsh/wpcomsh.php';
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 121 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

// 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' );

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

View workflow job for this annotation

GitHub Actions / Static analysis

UndefError PhanUndeclaredClassReference Reference to undeclared class \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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* @package Jetpack
*/

if ( class_exists( 'WPCOM_Features' ) ) {
return;
}

/**
* Class WPCOM_Features.
*/
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/tests/php/lib/mock-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function has_blog_sticker( $sticker ) {
function wp_cache_is_enabled() {}
}

if ( ! function_exists( 'wpcom_site_has_feature' ) && false === getenv( 'WITH_WPCOMSH' ) ) {
if ( ! function_exists( 'wpcom_site_has_feature' ) && false === getenv( 'JETPACK_TEST_WPCOMSH' ) ) {
/**
* Mock feature support.
*
Expand Down

0 comments on commit c5b68f4

Please sign in to comment.