From 8ac39ea1560890b0863e1b8a4efd206820565fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 6 Nov 2026 16:37:46 +0100 Subject: [PATCH 1/2] Turn off the garbage collector in WordPress PHPUnit tests PHP's cycle collector keeps walking a large heap during the run, and it rarely finds much to free in this short-lived process. Turning it off made the suite about 22% faster and raised peak memory from about 0.5 GB to about 4.2 GB, which fits the 16 GB CI runner. The WordPress test bootstrap already removes the PHP memory limit. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fa004320b..256a71e03 100644 --- a/composer.json +++ b/composer.json @@ -67,7 +67,7 @@ "wp-test-php": [ "@wp-test-ensure-env @no_additional_args", "@wp-test-remove-database @no_additional_args", - "cd wordpress && node tools/local-env/scripts/docker.js run --rm php php -d opcache.enable_cli=1 -d opcache.memory_consumption=256 -d opcache.jit=tracing -d opcache.jit_buffer_size=64M ./vendor/bin/phpunit @additional_args" + "cd wordpress && node tools/local-env/scripts/docker.js run --rm php php -d zend.enable_gc=0 -d opcache.enable_cli=1 -d opcache.memory_consumption=256 -d opcache.jit=tracing -d opcache.jit_buffer_size=64M ./vendor/bin/phpunit @additional_args" ], "wp-test-sqlite-plugin-php": [ "@wp-test-php /var/www/tests-sqlite-database-integration/phpunit" From 87ac3a4b2364a339a818d18ababf1f8b87058499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 6 Nov 2026 16:37:46 +0100 Subject: [PATCH 2/2] Use the low bcrypt cost in WordPress test class fixtures WP_UnitTestCase::set_up() lowers the bcrypt cost for each test, but wpSetUpBeforeClass() runs before it, so users created there hash passwords at PHP's default cost. Those hashes took most of the time spent in class fixtures. Apply the same cost for the whole run. --- wp-setup.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/wp-setup.sh b/wp-setup.sh index 3655f6f0d..e5e342030 100755 --- a/wp-setup.sh +++ b/wp-setup.sh @@ -62,15 +62,29 @@ sed -i.bak "s#{SQLITE_PLUGIN}#sqlite-database-integration/load.php#g" "$WP_DIR"/ echo "Rewriting helper class 'WpdbExposedMethodsForTesting' to extend WP_SQLite_DB..." sed -i.bak "s#class WpdbExposedMethodsForTesting extends wpdb {#class WpdbExposedMethodsForTesting extends WP_SQLite_DB {#g" "$WP_DIR"/tests/phpunit/includes/utils.php -# 6. Make wp-config.php changes immediately visible to E2E tests. +# 6. Use the low bcrypt cost of the test suite in class fixtures as well. +# WP_UnitTestCase::set_up() sets it for each test, which is too late for wpSetUpBeforeClass(). +echo "Lowering the bcrypt cost for test fixtures..." +cat << 'EOF' >> "$WP_DIR/tests/phpunit/includes/functions.php" + +function _sqlite_tests_lower_bcrypt_cost( $options, $algorithm ) { + if ( PASSWORD_BCRYPT === $algorithm ) { + $options['cost'] = 5; + } + return $options; +} +tests_add_filter( 'wp_hash_password_options', '_sqlite_tests_lower_bcrypt_cost', 1, 2 ); +EOF + +# 7. Make wp-config.php changes immediately visible to E2E tests. echo "Disabling the PHP OPcache revalidation delay..." printf '\nopcache.revalidate_freq = 0\n' >> "$WP_DIR/tools/local-env/php-config.ini" -# 7. Create the ".env" file early, so that Docker commands before "env:start" use it too. +# 8. Create the ".env" file early, so that Docker commands before "env:start" use it too. echo "Creating the '.env' file..." cp "$WP_DIR/.env.example" "$WP_DIR/.env" -# 8. Install dependencies. +# 9. Install dependencies. echo "Installing dependencies..." npm --prefix "$WP_DIR" install npm --prefix "$WP_DIR" run build:dev