Commit aa40b816448 for woocommerce

commit aa40b816448870d4c48d775d79e890ea078990b7
Author: Ján Mikláš <neosinner@gmail.com>
Date:   Thu Nov 19 12:18:53 2026 +0100

    Share PHP warning filtering for extension browser tests (#71125)

    * Add shared PHP warning log filtering

    * Add warning filter changelog entry

    * Ignore empty PHP warning path fragments

    * Ignore invalid PHP warning path fragments

diff --git a/packages/js/extension-tooling/README.md b/packages/js/extension-tooling/README.md
index e59aaf5c5dd..f359d7909f3 100644
--- a/packages/js/extension-tooling/README.md
+++ b/packages/js/extension-tooling/README.md
@@ -80,6 +80,10 @@ module.exports = defineConfig( playwrightDefaults( {

 Use the second config to set suite-specific projects, worker limits, storage state, and overrides.

+### Filter PHP debug logs
+
+Use `@woocommerce/extension-tooling/php-warning-filter` with the log text and the path fragments for the tested plugins. The filter returns matching PHP errors, warnings, notices and deprecations. The extension reads the log and checks the result in its warnings project.
+
 ## Webpack

 Import the helpers from the extension's webpack configuration. Keep the entry paths, output paths and match patterns in that configuration.
diff --git a/packages/js/extension-tooling/changelog/shared-extension-php-warning-filter b/packages/js/extension-tooling/changelog/shared-extension-php-warning-filter
new file mode 100644
index 00000000000..7adf67b8c80
--- /dev/null
+++ b/packages/js/extension-tooling/changelog/shared-extension-php-warning-filter
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Share PHP warning filtering for extension browser test logs.
diff --git a/packages/js/extension-tooling/package.json b/packages/js/extension-tooling/package.json
index e6ef0e804ab..37a16e99ccb 100644
--- a/packages/js/extension-tooling/package.json
+++ b/packages/js/extension-tooling/package.json
@@ -19,6 +19,7 @@
 		"./check-i18n": "./src/check-i18n.js",
 		"./playwright-defaults": "./src/playwright-defaults.js",
 		"./e2e-site-config": "./src/e2e-site-config.js",
+		"./php-warning-filter": "./src/php-warning-filter.js",
 		"./stylelint/legacy-scss": "./configs/stylelint-legacy-scss.json"
 	},
 	"bin": {
diff --git a/packages/js/extension-tooling/src/php-warning-filter.js b/packages/js/extension-tooling/src/php-warning-filter.js
new file mode 100644
index 00000000000..389d979dbb1
--- /dev/null
+++ b/packages/js/extension-tooling/src/php-warning-filter.js
@@ -0,0 +1,22 @@
+/**
+ * Return PHP log lines for the supplied plugin paths.
+ *
+ * @param {string}   log         PHP debug log contents.
+ * @param {string[]} pluginPaths Path fragments that identify the tested plugins.
+ * @return {string[]} Matching fatal errors, parse errors, warnings, notices and deprecations.
+ */
+module.exports = function filterPhpWarnings( log, pluginPaths ) {
+	const paths = pluginPaths.filter(
+		( pluginPath ) =>
+			typeof pluginPath === 'string' && pluginPath.trim().length > 0
+	);
+
+	return log
+		.split( '\n' )
+		.filter(
+			( line ) =>
+				/PHP (Fatal error|Parse error|Warning|Notice|Deprecated)/.test(
+					line
+				) && paths.some( ( pluginPath ) => line.includes( pluginPath ) )
+		);
+};
diff --git a/packages/js/extension-tooling/test/php-warning-filter.test.js b/packages/js/extension-tooling/test/php-warning-filter.test.js
new file mode 100644
index 00000000000..93a7926f303
--- /dev/null
+++ b/packages/js/extension-tooling/test/php-warning-filter.test.js
@@ -0,0 +1,39 @@
+/**
+ * External dependencies
+ */
+const assert = require( 'node:assert/strict' );
+const test = require( 'node:test' );
+
+/**
+ * Internal dependencies
+ */
+const filterPhpWarnings = require( '../src/php-warning-filter' );
+
+test( 'returns PHP issues for the supplied plugin paths in log order', () => {
+	const paths = [ '/plugins/test-extension/', '/workspace/checkout/' ];
+	const issues = [
+		'PHP Fatal error: something in /plugins/test-extension/a.php',
+		'PHP Parse error: something in /workspace/checkout/b.php',
+		'PHP Warning: something in /plugins/test-extension/c.php',
+		'PHP Notice: something in /workspace/checkout/d.php',
+		'PHP Deprecated: something in /plugins/test-extension/e.php',
+	];
+	const log = [
+		'PHP Warning: something in /plugins/test-extension-other/a.php',
+		...issues,
+		'Informational message in /plugins/test-extension/a.php',
+		'PHP Warning: undefined value 42 in /wp-includes/core.php',
+		'',
+	].join( '\n' );
+
+	assert.deepEqual( filterPhpWarnings( log, paths ), issues );
+	assert.deepEqual( filterPhpWarnings( log, [] ), [] );
+	assert.deepEqual( filterPhpWarnings( log, [ '' ] ), [] );
+	assert.deepEqual( filterPhpWarnings( log, [ '', ...paths ] ), issues );
+	assert.deepEqual( filterPhpWarnings( log, [ undefined, 42, '   ' ] ), [] );
+	assert.deepEqual(
+		filterPhpWarnings( log, [ undefined, ...paths ] ),
+		issues
+	);
+	assert.deepEqual( filterPhpWarnings( '', paths ), [] );
+} );