Skip to content

Commit 4597864

Browse files
kraftbjanomiex
andauthored
Dev: Only one WordPress (#41057)
Co-authored-by: Brad Jorsch <[email protected]>
1 parent 1807db5 commit 4597864

File tree

155 files changed

+1198
-2455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+1198
-2455
lines changed

.github/files/setup-wordpress-env.sh

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ git clone --depth=1 --branch "$WORDPRESS_TAG" git://develop.git.wordpress.org/ "
3333
# We need a built version of WordPress to test against, so download that into the src directory instead of what's in wordpress-develop.
3434
rm -rf "/tmp/wordpress-$WP_BRANCH/src"
3535
git clone --depth=1 --branch "$WORDPRESS_TAG" git://core.git.wordpress.org/ "/tmp/wordpress-$WP_BRANCH/src"
36+
37+
echo "::group::Setting up WordPress uploads directory"
38+
mkdir -p "/tmp/wordpress-$WP_BRANCH/src/wp-content/uploads"
39+
chmod -R 777 "/tmp/wordpress-$WP_BRANCH/src/wp-content/uploads"
40+
echo "::endgroup::"
41+
3642
echo "::endgroup::"
3743

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

108-
# Upgrade/downgrade WorDBless if necessary.
109-
if [[ ( "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ) && "$TEST_SCRIPT" == "test-php" ]]; then
110-
VER=$(composer --format=json --working-dir="$DIR" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version')
111-
if [[ -n "$VER" ]]; then
112-
INSVER=$WORDPRESS_TAG
113-
[[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER"
114-
echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\""
115-
# Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first.
116-
rm -rf "$DIR/wordpress"
117-
composer --working-dir="$DIR" require --dev roots/wordpress="$INSVER" roots/wordpress-no-content="$INSVER"
118-
fi
119-
fi
120-
121114
cp -r "$DIR" "/tmp/wordpress-$WP_BRANCH/src/wp-content/plugins/$NAME"
122115
# Plugin dir for tests in WP >= 5.6-beta1
123116
ln -s "/tmp/wordpress-$WP_BRANCH/src/wp-content/plugins/$NAME" "/tmp/wordpress-$WP_BRANCH/tests/phpunit/data/plugins/$NAME"

.github/workflows/tests.yml

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,6 @@ jobs:
8686
pnpm install
8787
echo "::endgroup::"
8888
89-
# If we're going to be making WorDBless use WP "nightlies", remove the relevant package from Composer's cache to get the latest version.
90-
if [[ "$WP_BRANCH" == 'trunk' && ( "$TEST_SCRIPT" == "test-php" || "$TEST_SCRIPT" == "test-coverage" ) ]]; then
91-
echo "::group::Clear composer cache for roots/wordpress"
92-
DIR=$(composer config cache-files-dir)
93-
rm -rf "$DIR/roots/wordpress" "$DIR/roots/wordpress-no-content"
94-
echo "::endgroup::"
95-
fi
96-
9789
- name: Detect changed projects
9890
id: changed
9991
run: |
@@ -110,9 +102,45 @@ jobs:
110102
echo "any-plugins=${ANY_PLUGINS}" >> "$GITHUB_OUTPUT"
111103
112104
- name: Select WordPress version
113-
if: steps.changed.outputs.any-plugins != 'true' && matrix.wp != 'none'
105+
if: matrix.wp != 'none'
114106
run: .github/files/select-wordpress-tag.sh
115107

108+
- name: Composer Install
109+
run: |
110+
# If we're going to be making WorDBless use WP "nightlies", remove the relevant package from Composer's cache to get the latest version.
111+
if [[ "$WP_BRANCH" == 'trunk' && ( "$TEST_SCRIPT" == "test-php" || "$TEST_SCRIPT" == "test-coverage" ) ]]; then
112+
echo "::group::Clear composer cache for roots/wordpress"
113+
DIR=$(composer config cache-files-dir)
114+
rm -rf "$DIR/roots/wordpress" "$DIR/roots/wordpress-no-content"
115+
echo "::endgroup::"
116+
fi
117+
118+
echo "::group::Composer"
119+
composer install --working-dir=tools/php-test-env
120+
121+
# Add WorDBless for various package tests that use uploads since concurrency can nuke uploads that are in use.
122+
# @todo Update WorDBless to be able to use a customized upload dir, do that, and remove this.
123+
if [[ "$TEST_SCRIPT" =~ ^test-(php|coverage)$ ]]; then
124+
VER=$( jq -r '.require["automattic/wordbless"]' tools/php-test-env/composer.json )
125+
for pkg in packages/image-cdn packages/publicize packages/videopress; do
126+
echo "Adding WordBless for $pkg tests"
127+
composer require --working-dir="projects/$pkg" "automattic/wordbless:$VER" --dev --no-update
128+
done
129+
fi
130+
131+
if [[ ( "$TEST_SCRIPT" == "test-php" || "$TEST_SCRIPT" == "test-coverage" ) && ( "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ) ]]; then
132+
VER=$(composer --format=json --working-dir="tools/php-test-env" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version')
133+
if [[ -n "$VER" ]]; then
134+
INSVER=$WORDPRESS_TAG
135+
[[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER"
136+
echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\""
137+
# Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first.
138+
rm -rf "tools/php-test-env/wordpress"
139+
composer --working-dir="tools/php-test-env" require --dev "roots/wordpress:$INSVER" "roots/wordpress-no-content:$INSVER"
140+
fi
141+
fi
142+
echo "::endgroup::"
143+
116144
- name: Setup WordPress environment for plugin tests
117145
env:
118146
API_TOKEN_GITHUB: ${{ secrets.GITHUB_TOKEN }}
@@ -196,18 +224,6 @@ jobs:
196224
echo 'Platform reqs failed, running `composer update`'
197225
composer --working-dir="$DIR" update
198226
fi
199-
200-
if [[ "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ]]; then
201-
VER=$(composer --format=json --working-dir="$DIR" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version')
202-
if [[ -n "$VER" ]]; then
203-
INSVER=$WORDPRESS_TAG
204-
[[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER"
205-
echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\""
206-
# Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first.
207-
rm -rf "$DIR/wordpress"
208-
composer --working-dir="$DIR" require --dev roots/wordpress="$INSVER" roots/wordpress-no-content="$INSVER"
209-
fi
210-
fi
211227
fi
212228
fi
213229

.phan/config.base.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ function make_phan_config( $dir, $options = array() ) {
137137
$internal_stubs[ $stub ] = $stub_file_path;
138138
}
139139

140+
// Check if test-environment is a dependency and add WorDBless if it is
141+
$composer_json = $dir . '/composer.json';
142+
if ( file_exists( $composer_json ) ) {
143+
$composer_data = json_decode( file_get_contents( $composer_json ), true );
144+
foreach ( array( 'require', 'require-dev' ) as $require_type ) {
145+
if ( isset( $composer_data[ $require_type ]['automattic/jetpack-test-environment'] ) ) {
146+
// Use absolute path to ensure WorDBless is found
147+
$wordbless_path = dirname( __DIR__ ) . '/tools/php-test-env/vendor/automattic/wordbless';
148+
if ( is_dir( $wordbless_path ) ) {
149+
// Only include the src directory
150+
$options['directory_list'][] = $wordbless_path . '/src';
151+
// Exclude from analysis
152+
$options['exclude_analysis_directory_list'][] = $wordbless_path;
153+
}
154+
break;
155+
}
156+
}
157+
}
158+
140159
$config = array(
141160
// Apparently this is only useful when upgrading from php 5, not for 7-to-8.
142161
'backward_compatibility_checks' => false,

.phan/config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
// Ignore stuff in various subdirs too.
2828
'.*/node_modules/',
2929
'tools/docker/',
30+
'tools/php-test-env/wordpress/',
31+
'tools/php-test-env/vendor/',
3032
// 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.)
3133
'.phan/stubs/',
3234
),

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@
6969
],
7070
"test-js": [
7171
"cd tools/cli && pnpm test"
72+
],
73+
"post-install-cmd": [
74+
"cd tools/php-test-env && composer install"
75+
],
76+
"post-update-cmd": [
77+
"cd tools/php-test-env && composer update"
7278
]
7379
},
7480
"scripts-descriptions": {

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/automated-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ There are normally two reasons why you would choose integration over unit tests:
4141
Normally, integration tests for packages rely on various mocking solutions available:
4242

4343
- [brain/monkey](https://packagist.org/packages/brain/monkey) - For mocking and stubbing WordPress functions and classes.
44-
- [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.
44+
- [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.
4545

4646
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).
4747

docs/monorepo.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,12 @@ We currently make use of the following packages in testing; it's encouraged to u
268268
* Do not use `Yoast\PHPUnitPolyfills\TestCases\TestCase` or `Yoast\PHPUnitPolyfills\TestCases\XTestCase`. Just use the `@before`, `@after`, `@beforeClass`, and `@afterClass` annotations directly.
269269
* PHPUnit's built-in mocking is used for class mocks.
270270
* [brain/monkey](https://packagist.org/packages/brain/monkey) is used for mocking functions, and can also provide some functions for minimal WordPress compatibility.
271-
* [automattic/wordbless](https://packagist.org/packages/automattic/wordbless) is used to pull in WordPress for testing.
272-
* If using both Brain Monkey and WorDBless, note the following requirements:
273-
* You must `require_once __DIR__ . '/../../vendor/antecedent/patchwork/Patchwork.php';` in `bootstrap.php` before WorDBless's setup, so Brain Monkey can mock WordPress functions.
271+
* [automattic/jetpack-test-environment](../projects/packages/test-environment/README.md) is used to pull in WordPress for testing.
272+
* If using both Brain Monkey and the Jetpack Test Environment, note the following requirements:
273+
* 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.
274274
* 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.
275+
* To initiate the Jetpack Test Environment, call `\Automattic\Jetpack\Test_Environment\Bootstrap::init();` in `bootstrap.php`.
276+
* See the [Jetpack Test Environment README](../projects/packages/test-environment/README.md) for more details.
275277
276278
#### PHP tests for plugins
277279
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: changed
3+
Comment: Updating the method of loading WordPress for testing. No functional change and the tests don't currently exist either way :)
4+
5+

projects/packages/account-protection/composer.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"require-dev": {
1010
"yoast/phpunit-polyfills": "^1.1.1",
1111
"automattic/jetpack-changelogger": "@dev",
12-
"automattic/wordbless": "dev-master"
12+
"automattic/jetpack-test-environment": "@dev"
1313
},
1414
"autoload": {
1515
"classmap": [
@@ -22,8 +22,6 @@
2222
"phpunit": [
2323
"./vendor/phpunit/phpunit/phpunit --colors=always"
2424
],
25-
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
26-
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy",
2725
"test-coverage": [
2826
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-php \"$COVERAGE_DIR/php.cov\""
2927
],
@@ -42,11 +40,6 @@
4240
],
4341
"minimum-stability": "dev",
4442
"prefer-stable": true,
45-
"config": {
46-
"allow-plugins": {
47-
"roots/wordpress-core-installer": true
48-
}
49-
},
5043
"extra": {
5144
"autotagger": true,
5245
"branch-alias": {

projects/packages/account-protection/tests/php/bootstrap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
* Include the composer autoloader.
1010
*/
1111
require_once __DIR__ . '/../../vendor/autoload.php';
12+
13+
// Initialize WordPress test environment
14+
\Automattic\Jetpack\Test_Environment::init();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: added
3+
Comment: Update development platform only
4+
5+

projects/packages/admin-ui/composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"yoast/phpunit-polyfills": "^1.1.1",
1111
"automattic/jetpack-changelogger": "@dev",
1212
"automattic/jetpack-logo": "@dev",
13-
"automattic/wordbless": "^0.4.2"
13+
"automattic/jetpack-test-environment": "@dev"
1414
},
1515
"suggest": {
1616
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
@@ -29,9 +29,7 @@
2929
],
3030
"test-php": [
3131
"@composer phpunit"
32-
],
33-
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
34-
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy"
32+
]
3533
},
3634
"repositories": [
3735
{

projects/packages/admin-ui/tests/php/bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212

1313
define( 'WP_DEBUG', true );
1414

15-
\WorDBless\Load::load();
15+
// Initialize WordPress test environment
16+
\Automattic\Jetpack\Test_Environment::init();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: added
3+
Comment: Update development platform only
4+
5+

projects/packages/backup-helper-script-manager/composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"require-dev": {
1010
"yoast/phpunit-polyfills": "^1.1.1",
1111
"automattic/jetpack-changelogger": "@dev",
12-
"automattic/wordbless": "^0.4.2"
12+
"automattic/jetpack-test-environment": "@dev"
1313
},
1414
"suggest": {
1515
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
@@ -28,9 +28,7 @@
2828
],
2929
"test-php": [
3030
"@composer phpunit"
31-
],
32-
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
33-
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy"
31+
]
3432
},
3533
"repositories": [
3634
{

projects/packages/backup-helper-script-manager/tests/php/bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212

1313
define( 'WP_DEBUG', true );
1414

15-
\WorDBless\Load::load();
15+
// Initialize WordPress test environment
16+
\Automattic\Jetpack\Test_Environment::init();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: added
3+
Comment: Update development platform only
4+
5+

projects/packages/backup/composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"require-dev": {
2020
"automattic/jetpack-changelogger": "@dev",
2121
"yoast/phpunit-polyfills": "^1.1.1",
22-
"automattic/wordbless": "^0.4.2"
22+
"automattic/jetpack-test-environment": "@dev"
2323
},
2424
"suggest": {
2525
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
@@ -43,8 +43,6 @@
4343
"test-php": [
4444
"@composer phpunit"
4545
],
46-
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
47-
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy",
4846
"build-development": [
4947
"pnpm run build"
5048
],

projects/packages/backup/tests/php/bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212

1313
define( 'WP_DEBUG', true );
1414

15-
\WorDBless\Load::load();
15+
// Initialize WordPress test environment
16+
\Automattic\Jetpack\Test_Environment::init();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: added
3+
Comment: Update development platform only
4+
5+

projects/packages/blaze/composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"require-dev": {
1717
"yoast/phpunit-polyfills": "^1.1.1",
1818
"automattic/jetpack-changelogger": "@dev",
19-
"automattic/wordbless": "^0.4.2"
19+
"automattic/jetpack-test-environment": "@dev"
2020
},
2121
"suggest": {
2222
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
@@ -45,9 +45,7 @@
4545
"watch": [
4646
"Composer\\Config::disableProcessTimeout",
4747
"pnpm run watch"
48-
],
49-
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
50-
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy"
48+
]
5149
},
5250
"repositories": [
5351
{

0 commit comments

Comments
 (0)