Commit 61d5b96f0e4 for woocommerce

commit 61d5b96f0e4d4c2e1c6db33b6416e9a6101b84c1
Author: Ján Mikláš <neosinner@gmail.com>
Date:   Fri Nov 27 12:31:13 2026 +0100

    Shard WooCommerce PHPUnit jobs on PHP 7.4 (#71516)

    * Shard pre-release CI with built-in PHPUnit suites

    * Add changelog entry for PHPUnit sharding

    * Shard stable PHP 7.4 PHPUnit jobs

    * Update the PHPUnit sharding changelog

diff --git a/bin/test-php-ci.sh b/bin/test-php-ci.sh
index d47df1b0f2e..6d9dcacc91c 100755
--- a/bin/test-php-ci.sh
+++ b/bin/test-php-ci.sh
@@ -13,6 +13,7 @@
 # versions and commands come from `pnpm utils ci-jobs`, as in CI. Cells start
 # without `--update` so they stay warm, unless their WordPress is not the
 # version the cell needs; `--fresh` starts them as CI does.
+# Pick sharded cells by index from --list. --tests selects across both shards.
 # One invocation at a time.

 set -euo pipefail
@@ -205,6 +206,23 @@ else
 	done
 fi

+# A manual selection runs once per PHP/WordPress cell, even if CI uses two shards.
+if [[ ${#tests[@]} -gt 0 ]]; then
+	narrowed=()
+	sharded_cells=()
+	for index in "${selected[@]}"; do
+		row="${cell_rows[$(( index - 1 ))]}"
+		command="$(field "$row" 3)"
+		if [[ "$command" == *" --testsuite="* ]]; then
+			key="$(field "$row" 6):${command% --testsuite=*}"
+			[[ " ${sharded_cells[*]:-} " == *" $key "* ]] && continue
+			sharded_cells+=( "$key" )
+		fi
+		narrowed+=( "$index" )
+	done
+	selected=( "${narrowed[@]}" )
+fi
+
 # Install as CI does for a unit:php job.
 run composer install --working-dir="$project_dir" --quiet &
 composer_pid=$!
@@ -298,17 +316,21 @@ run_group() {
 	for index in "${selected[@]}"; do
 		local row="${cell_rows[$(( index - 1 ))]}"
 		[[ "$(field "$row" 6)" == "$slug" ]] || continue
-		local name command log start_at rc
+		local name log start_at rc
+		local -a command_args
 		name="$(field "$row" 2)"
-		command="$(field "$row" 3)"
-		command="${command/test:php:env/test:php:env:run}"
+		read -r -a command_args <<< "$(field "$row" 3)"
+		command_args[0]="${command_args[0]/test:php:env/test:php:env:run}"
+		if [[ ${#tests[@]} -gt 0 && "${command_args[1]:-}" == --testsuite=* ]]; then
+			command_args=( "${command_args[0]}" )
+		fi
 		log="$tmp/cell-$index.log"
 		envs=()
 		while IFS= read -r line; do envs+=( "$line" ); done < <( cell_env "$(field "$row" 7)" )
 		start_at=$(date +%s)
 		rc=0
 		if truncate_action_scheduler "$config" > "$log" 2>&1; then
-			CI=true WC_TEST_ENV_CONFIG="$config" env ${envs[@]+"${envs[@]}"} pnpm --filter="$project" "$command" ${phpunit_args[@]+"${phpunit_args[@]}"} >> "$log" 2>&1 || rc=$?
+			CI=true WC_TEST_ENV_CONFIG="$config" env ${envs[@]+"${envs[@]}"} pnpm --filter="$project" "${command_args[@]}" ${phpunit_args[@]+"${phpunit_args[@]}"} >> "$log" 2>&1 || rc=$?
 		else
 			rc=$?
 			echo "could not reset the Action Scheduler tables" >> "$log"
diff --git a/plugins/woocommerce/changelog/dev-phpunit-prerelease-shards b/plugins/woocommerce/changelog/dev-phpunit-prerelease-shards
new file mode 100644
index 00000000000..8fde08f6295
--- /dev/null
+++ b/plugins/woocommerce/changelog/dev-phpunit-prerelease-shards
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Shard the stable and pre-release PHP 7.4 PHPUnit checks to reduce CI timeouts.
diff --git a/plugins/woocommerce/package.json b/plugins/woocommerce/package.json
index 9322c888550..975e3667c5e 100644
--- a/plugins/woocommerce/package.json
+++ b/plugins/woocommerce/package.json
@@ -232,7 +232,10 @@
 					"name": "PHP: 7.4 WP: latest - 1",
 					"testType": "unit:php",
 					"command": "test:php:env",
-					"shardingArguments": [],
+					"shardingArguments": [
+						"--testsuite=wc-phpunit-legacy,wc-phpunit-main-includes",
+						"--testsuite=wc-phpunit-main-other"
+					],
 					"onlyForDependencies": [
 						"@woocommerce/email-editor-config"
 					],
@@ -268,7 +271,10 @@
 					"optional": true,
 					"testType": "unit:php",
 					"command": "test:php:env",
-					"shardingArguments": [],
+					"shardingArguments": [
+						"--testsuite=wc-phpunit-legacy,wc-phpunit-main-includes",
+						"--testsuite=wc-phpunit-main-other"
+					],
 					"onlyForDependencies": [],
 					"changes": [
 						"tests/legacy/**",
diff --git a/plugins/woocommerce/phpunit.xml b/plugins/woocommerce/phpunit.xml
index 8df1fd5ce7d..b6868fbff39 100644
--- a/plugins/woocommerce/phpunit.xml
+++ b/plugins/woocommerce/phpunit.xml
@@ -21,6 +21,17 @@
 			     include-time (top-level HTML and `echo`). Exclude to silence them. -->
 			<exclude>./tests/php/src/Internal/EmailEditor/WCTransactionalEmails/fixtures</exclude>
 		</testsuite>
+		<testsuite name="wc-phpunit-main-includes">
+			<directory suffix=".php">./tests/php/includes</directory>
+		</testsuite>
+		<testsuite name="wc-phpunit-main-other">
+			<directory suffix=".php">./tests/php</directory>
+			<!-- Exclude the includes shard and keep the other exclusions in sync with wc-phpunit-main. -->
+			<exclude>./tests/php/includes</exclude>
+			<exclude>./tests/php/helpers</exclude>
+			<exclude>./tests/php/src/Blocks/BlockPatterns/patterns</exclude>
+			<exclude>./tests/php/src/Internal/EmailEditor/WCTransactionalEmails/fixtures</exclude>
+		</testsuite>
 	</testsuites>
 	<listeners>
 		<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener">
diff --git a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Admin/SettingsControllerTests.php b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Admin/SettingsControllerTests.php
index f579d75ac31..e15aa8c7411 100644
--- a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Admin/SettingsControllerTests.php
+++ b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Admin/SettingsControllerTests.php
@@ -12,6 +12,8 @@ use WC_Settings_Advanced;
 use WC_Settings_Products;
 use WP_REST_Request;

+require_once dirname( __DIR__, 4 ) . '/includes/settings/class-wc-settings-unit-test-case.php';
+
 /**
  * SettingsControllerTests data tests.
  */