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

Dev: Only one WordPress #41057

Merged
merged 39 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4cd499e
Initial commit of a centralized test install of WordPress
kraftbj Jan 13, 2025
97e5a9a
Use new test package for various projects
kraftbj Jan 16, 2025
965e2f4
Update Image CDN tests
kraftbj Jan 21, 2025
ef8c04f
try: shouldn't we select wp on plugins?
kraftbj Jan 21, 2025
6db0ea3
Use dedicated WorDBless for image-cdn
kraftbj Jan 22, 2025
e4cc3c9
Restore cleanup of wordbless
kraftbj Jan 22, 2025
6586305
Update changelog to only impacted packages
kraftbj Jan 22, 2025
5263cee
Restore bootstrap file
kraftbj Jan 22, 2025
16fdf6f
Always determine WP version
kraftbj Jan 23, 2025
88b805e
lock files
kraftbj Jan 23, 2025
448bf99
Revise test runner
kraftbj Jan 23, 2025
85082fa
Do not phan the test env
kraftbj Jan 23, 2025
9700109
Only exclude the wordpress dir from the test env
kraftbj Jan 23, 2025
a9cad95
Merge remote-tracking branch 'origin/trunk' into try/one-wordpress-to…
kraftbj Jan 24, 2025
6b12c53
apt-get clean not needed on ubuntu docker builds
kraftbj Jan 24, 2025
c845cf9
Merge remote-tracking branch 'origin/trunk' into try/one-wordpress-to…
kraftbj Jan 27, 2025
24624b7
Exclude test env vendor dir
kraftbj Jan 27, 2025
8b0e6dc
Add WorDBless as an independent requirement for Publicize tests
kraftbj Jan 27, 2025
215b875
Update the .phan config base to selectively add wordbless
kraftbj Jan 27, 2025
1f45183
Override the directories for the test-env package so it'll check dire…
kraftbj Jan 27, 2025
80f4a88
only include wordbless src to avoid the wordbless test files from bei…
kraftbj Jan 27, 2025
f1be2d1
try: totally exclude to prevent phpcs declaration warnings
kraftbj Jan 27, 2025
7aa668e
Add pcov ext for the docker env
kraftbj Jan 27, 2025
f4ce5bc
Add VideoPress to the concurrent test problem set. DRY it later
kraftbj Jan 27, 2025
36dff46
Revert "Add pcov ext for the docker env"
kraftbj Jan 27, 2025
bc0141c
Merge remote-tracking branch 'origin/trunk' into try/one-wordpress-to…
kraftbj Jan 28, 2025
10702fd
Merge remote-tracking branch 'origin/trunk' into try/one-wordpress-to…
kraftbj Jan 29, 2025
9388138
Use new test package for account protection package
kraftbj Jan 29, 2025
071523d
Update cli generate command to use test package instead of wordbless
kraftbj Jan 29, 2025
2d7f73f
Add readme to test-environment package
kraftbj Jan 29, 2025
5d5525d
Add readme to tools/php-test-env pointing to the test environment readme
kraftbj Jan 29, 2025
9963fc8
Remove unused gitattributes from boost plugin
kraftbj Jan 29, 2025
f2ac9f8
update docs to the one true WordPress way
kraftbj Jan 29, 2025
6aa16f0
changelog
kraftbj Jan 29, 2025
e08466f
defer this to a later PR
kraftbj Jan 29, 2025
a7f713d
Clean up temporary wordbless install
kraftbj Jan 29, 2025
059167f
Remove new php ext for another PR
kraftbj Jan 29, 2025
4fb93fd
Merge branch 'try/one-wordpress-to-rule-them-all' of github.com:Autom…
kraftbj Jan 29, 2025
b78adc5
Restore Dockerfile.monorepo to original
kraftbj Jan 29, 2025
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
19 changes: 6 additions & 13 deletions .github/files/setup-wordpress-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ git clone --depth=1 --branch "$WORDPRESS_TAG" git://develop.git.wordpress.org/ "
# We need a built version of WordPress to test against, so download that into the src directory instead of what's in wordpress-develop.
rm -rf "/tmp/wordpress-$WP_BRANCH/src"
git clone --depth=1 --branch "$WORDPRESS_TAG" git://core.git.wordpress.org/ "/tmp/wordpress-$WP_BRANCH/src"

echo "::group::Setting up WordPress uploads directory"
mkdir -p "/tmp/wordpress-$WP_BRANCH/src/wp-content/uploads"
chmod -R 777 "/tmp/wordpress-$WP_BRANCH/src/wp-content/uploads"
echo "::endgroup::"

echo "::endgroup::"

if [[ -n "$GITHUB_ENV" ]]; then
Expand Down Expand Up @@ -105,19 +111,6 @@ for PLUGIN in projects/plugins/*/composer.json; do
fi
cd "$BASE"

# Upgrade/downgrade WorDBless if necessary.
if [[ ( "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ) && "$TEST_SCRIPT" == "test-php" ]]; then
VER=$(composer --format=json --working-dir="$DIR" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version')
if [[ -n "$VER" ]]; then
INSVER=$WORDPRESS_TAG
[[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER"
echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\""
# Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first.
rm -rf "$DIR/wordpress"
composer --working-dir="$DIR" require --dev roots/wordpress="$INSVER" roots/wordpress-no-content="$INSVER"
fi
fi

cp -r "$DIR" "/tmp/wordpress-$WP_BRANCH/src/wp-content/plugins/$NAME"
# Plugin dir for tests in WP >= 5.6-beta1
ln -s "/tmp/wordpress-$WP_BRANCH/src/wp-content/plugins/$NAME" "/tmp/wordpress-$WP_BRANCH/tests/phpunit/data/plugins/$NAME"
Expand Down
66 changes: 45 additions & 21 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,6 @@ jobs:
pnpm install
echo "::endgroup::"

# If we're going to be making WorDBless use WP "nightlies", remove the relevant package from Composer's cache to get the latest version.
if [[ "$WP_BRANCH" == 'trunk' && ( "$TEST_SCRIPT" == "test-php" || "$TEST_SCRIPT" == "test-coverage" ) ]]; then
echo "::group::Clear composer cache for roots/wordpress"
DIR=$(composer config cache-files-dir)
rm -rf "$DIR/roots/wordpress" "$DIR/roots/wordpress-no-content"
echo "::endgroup::"
fi

- name: Detect changed projects
id: changed
run: |
Expand All @@ -110,9 +102,53 @@ jobs:
echo "any-plugins=${ANY_PLUGINS}" >> "$GITHUB_OUTPUT"

- name: Select WordPress version
if: steps.changed.outputs.any-plugins != 'true' && matrix.wp != 'none'
if: matrix.wp != 'none'
run: .github/files/select-wordpress-tag.sh

- name: Composer Install
run: |
# If we're going to be making WorDBless use WP "nightlies", remove the relevant package from Composer's cache to get the latest version.
if [[ "$WP_BRANCH" == 'trunk' && ( "$TEST_SCRIPT" == "test-php" || "$TEST_SCRIPT" == "test-coverage" ) ]]; then
echo "::group::Clear composer cache for roots/wordpress"
DIR=$(composer config cache-files-dir)
rm -rf "$DIR/roots/wordpress" "$DIR/roots/wordpress-no-content"
echo "::endgroup::"
fi

echo "::group::Composer"
composer install --working-dir=tools/php-test-env

# Add WorDBless for image-cdn package tests since concurrency can nuke uploads that are in use.
if [[ "$TEST_SCRIPT" =~ ^test-(php|coverage)$ ]] && jq -e '.name == "automattic/jetpack-image-cdn"' projects/packages/image-cdn/composer.json >/dev/null; then
echo "Adding WordBless for image-cdn tests"
composer require --working-dir=projects/packages/image-cdn automattic/wordbless:^0.4.2 --dev
fi

# Add WorDBles for publicize package tests since concurrency can nuke uploads that are in use.
if [[ "$TEST_SCRIPT" =~ ^test-(php|coverage)$ ]] && jq -e '.name == "automattic/jetpack-publicize"' projects/packages/publicize/composer.json >/dev/null; then
echo "Adding WorDBless for publicize tests"
composer require --working-dir=projects/packages/publicize automattic/wordbless:^0.4.2 --dev
fi

# Add WorDBles for videopress package tests since concurrency can nuke uploads that are in use.
if [[ "$TEST_SCRIPT" =~ ^test-(php|coverage)$ ]] && jq -e '.name == "automattic/jetpack-videopress"' projects/packages/videopress/composer.json >/dev/null; then
echo "Adding WorDBless for videopress tests"
composer require --working-dir=projects/packages/videopress automattic/wordbless:^0.4.2 --dev
fi

if [[ ( "$TEST_SCRIPT" == "test-php" || "$TEST_SCRIPT" == "test-coverage" ) && ( "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ) ]]; then
VER=$(composer --format=json --working-dir="tools/php-test-env" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version')
if [[ -n "$VER" ]]; then
INSVER=$WORDPRESS_TAG
[[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER"
echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\""
# Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first.
rm -rf "tools/php-test-env/wordpress"
composer --working-dir="tools/php-test-env" require --dev "roots/wordpress:$INSVER" "roots/wordpress-no-content:$INSVER"
fi
fi
echo "::endgroup::"

- name: Setup WordPress environment for plugin tests
env:
API_TOKEN_GITHUB: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -196,18 +232,6 @@ jobs:
echo 'Platform reqs failed, running `composer update`'
composer --working-dir="$DIR" update
fi

if [[ "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ]]; then
VER=$(composer --format=json --working-dir="$DIR" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version')
if [[ -n "$VER" ]]; then
INSVER=$WORDPRESS_TAG
[[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER"
echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\""
# Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first.
rm -rf "$DIR/wordpress"
composer --working-dir="$DIR" require --dev roots/wordpress="$INSVER" roots/wordpress-no-content="$INSVER"
fi
fi
fi
fi

Expand Down
19 changes: 19 additions & 0 deletions .phan/config.base.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,25 @@ function make_phan_config( $dir, $options = array() ) {
$internal_stubs[ $stub ] = $stub_file_path;
}

// Check if test-environment is a dependency and add WorDBless if it is
$composer_json = $dir . '/composer.json';
if ( file_exists( $composer_json ) ) {
$composer_data = json_decode( file_get_contents( $composer_json ), true );
foreach ( array( 'require', 'require-dev' ) as $require_type ) {
if ( isset( $composer_data[ $require_type ]['automattic/jetpack-test-environment'] ) ) {
// Use absolute path to ensure WorDBless is found
$wordbless_path = dirname( __DIR__ ) . '/tools/php-test-env/vendor/automattic/wordbless';
if ( is_dir( $wordbless_path ) ) {
// Only include the src directory
$options['directory_list'][] = $wordbless_path . '/src';
// Exclude from analysis
$options['exclude_analysis_directory_list'][] = $wordbless_path;
Comment on lines +146 to +149
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this works, IMO it would be a little cleaner to have an array that works like $extra_stubs, which gets array_merged into the two config entries below, instead of changing the $options directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm down for fixing this in a follow-up. I'm itchy to get it in and iterate on it vs holding up the PR too much longer.

}
break;
}
}
}

$config = array(
// Apparently this is only useful when upgrading from php 5, not for 7-to-8.
'backward_compatibility_checks' => false,
Expand Down
2 changes: 2 additions & 0 deletions .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
// Ignore stuff in various subdirs too.
'.*/node_modules/',
'tools/docker/',
'tools/php-test-env/wordpress/',
'tools/php-test-env/vendor/',
// Don't load the stubs. (if we need to start loading _a_ stub for the "monorepo", do like `(?!filename\.php)` to exclude it from the exclusion.)
'.phan/stubs/',
),
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
],
"test-js": [
"cd tools/cli && pnpm test"
],
"post-install-cmd": [
"cd tools/php-test-env && composer install"
],
"post-update-cmd": [
"cd tools/php-test-env && composer update"
]
},
"scripts-descriptions": {
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/automated-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ There are normally two reasons why you would choose integration over unit tests:
Normally, integration tests for packages rely on various mocking solutions available:

- [brain/monkey](https://packagist.org/packages/brain/monkey) - For mocking and stubbing WordPress functions and classes.
- [automattic/wordbless](https://packagist.org/packages/automattic/wordbless) is used to pull in WordPress for testing. As name implies, it's a lightweight version of WordPress, without database and other limitations.
- [automattic/jetpack-test-environment](../projects/packages/test-environment/README.md) is used to pull in WordPress for testing. It calls in a lightweight version of WordPress (via the [WorDBless](https://packagist.org/packages/automattic/wordbless) package) and provides a way to run tests in a WordPress environment. We use the jetpack-test-environment package within the monorepo to only need one install of WordPress for the entire monorepo.

There are a lot of examples on how to use these tools in the `/projects/packages` folder, such as [here](/projects/packages/connection/tests/php/test_Manager_integration.php).

Expand Down
8 changes: 5 additions & 3 deletions docs/monorepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ We currently make use of the following packages in testing; it's encouraged to u
* Do not use `Yoast\PHPUnitPolyfills\TestCases\TestCase` or `Yoast\PHPUnitPolyfills\TestCases\XTestCase`. Just use the `@before`, `@after`, `@beforeClass`, and `@afterClass` annotations directly.
* PHPUnit's built-in mocking is used for class mocks.
* [brain/monkey](https://packagist.org/packages/brain/monkey) is used for mocking functions, and can also provide some functions for minimal WordPress compatibility.
* [automattic/wordbless](https://packagist.org/packages/automattic/wordbless) is used to pull in WordPress for testing.
* If using both Brain Monkey and WorDBless, note the following requirements:
* You must `require_once __DIR__ . '/../../vendor/antecedent/patchwork/Patchwork.php';` in `bootstrap.php` before WorDBless's setup, so Brain Monkey can mock WordPress functions.
* [automattic/jetpack-test-environment](../projects/packages/test-environment/README.md) is used to pull in WordPress for testing.
* If using both Brain Monkey and the Jetpack Test Environment, note the following requirements:
* You must `require_once __DIR__ . '/../../vendor/antecedent/patchwork/Patchwork.php';` in `bootstrap.php` before the Jetpack Test Environment's setup, so Brain Monkey can mock WordPress functions.
* Follow Brain Monkey's [functions-setup.md](https://github.com/Brain-WP/BrainMonkey/blob/master/docs/functions-testing-tools/functions-setup.md) instead of [wordpress-setup.md](https://github.com/Brain-WP/BrainMonkey/blob/master/docs/wordpress-specific-tools/wordpress-setup.md); don't call `Monkey\setUp()` or try to use its WordPress-specific tools.
* To initiate the Jetpack Test Environment, call `\Automattic\Jetpack\Test_Environment\Bootstrap::init();` in `bootstrap.php`.
* See the [Jetpack Test Environment README](../projects/packages/test-environment/README.md) for more details.

#### PHP tests for plugins

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updating the method of loading WordPress for testing. No functional change and the tests don't currently exist either way :)


9 changes: 1 addition & 8 deletions projects/packages/account-protection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"require-dev": {
"yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "@dev",
"automattic/wordbless": "dev-master"
"automattic/jetpack-test-environment": "@dev"
},
"autoload": {
"classmap": [
Expand All @@ -22,8 +22,6 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-php \"$COVERAGE_DIR/php.cov\""
],
Expand All @@ -42,11 +40,6 @@
],
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"allow-plugins": {
"roots/wordpress-core-installer": true
}
},
"extra": {
"autotagger": true,
"branch-alias": {
Expand Down
3 changes: 3 additions & 0 deletions projects/packages/account-protection/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
* Include the composer autoloader.
*/
require_once __DIR__ . '/../../vendor/autoload.php';

// Initialize WordPress test environment
\Automattic\Jetpack\Test_Environment::init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Update development platform only


6 changes: 2 additions & 4 deletions projects/packages/admin-ui/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "@dev",
"automattic/jetpack-logo": "@dev",
"automattic/wordbless": "^0.4.2"
"automattic/jetpack-test-environment": "@dev"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
Expand All @@ -29,9 +29,7 @@
],
"test-php": [
"@composer phpunit"
],
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy"
]
},
"repositories": [
{
Expand Down
3 changes: 2 additions & 1 deletion projects/packages/admin-ui/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@

define( 'WP_DEBUG', true );

\WorDBless\Load::load();
// Initialize WordPress test environment
\Automattic\Jetpack\Test_Environment::init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Update development platform only


6 changes: 2 additions & 4 deletions projects/packages/backup-helper-script-manager/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"require-dev": {
"yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "@dev",
"automattic/wordbless": "^0.4.2"
"automattic/jetpack-test-environment": "@dev"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
Expand All @@ -28,9 +28,7 @@
],
"test-php": [
"@composer phpunit"
],
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy"
]
},
"repositories": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@

define( 'WP_DEBUG', true );

\WorDBless\Load::load();
// Initialize WordPress test environment
\Automattic\Jetpack\Test_Environment::init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Update development platform only


4 changes: 1 addition & 3 deletions projects/packages/backup/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"require-dev": {
"automattic/jetpack-changelogger": "@dev",
"yoast/phpunit-polyfills": "^1.1.1",
"automattic/wordbless": "^0.4.2"
"automattic/jetpack-test-environment": "@dev"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
Expand All @@ -43,8 +43,6 @@
"test-php": [
"@composer phpunit"
],
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"build-development": [
"pnpm run build"
],
Expand Down
3 changes: 2 additions & 1 deletion projects/packages/backup/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@

define( 'WP_DEBUG', true );

\WorDBless\Load::load();
// Initialize WordPress test environment
\Automattic\Jetpack\Test_Environment::init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added
Comment: Update development platform only


Loading
Loading