Commit f041640418b for woocommerce

commit f041640418b7be030a0f6168505331c722de08fd
Author: Ján Mikláš <neosinner@gmail.com>
Date:   Tue Nov 17 15:16:05 2026 +0100

    Share PHP debug log checks in Playwright (#71039)

    * Share PHP debug log checks in Playwright

    * Add Playwright debug log changelog

    * Verify the exact Playwright log marker

diff --git a/packages/js/e2e-utils-playwright/README.md b/packages/js/e2e-utils-playwright/README.md
index a37d627c6ef..9d4f183e3e7 100644
--- a/packages/js/e2e-utils-playwright/README.md
+++ b/packages/js/e2e-utils-playwright/README.md
@@ -33,6 +33,22 @@ test('can add products to cart', async ({ page }) => {
 });
 ```

+## PHP debug log checks
+
+Use `readPhpDebugLog` with a WordPress test site at the base URL's origin root. The site needs a test-only handler on `/` that writes a marker and a readable log at `/wp-content/debug.log`. Supply the handler's query parameter and log prefix. Filter the verified log for the plugin paths and PHP messages your suite checks.
+
+```js
+import { readPhpDebugLog } from '@woocommerce/e2e-utils-playwright';
+
+test('debug.log contains no PHP issues from the plugin', async ({ request }) => {
+  const log = await readPhpDebugLog(request, {
+    queryParameter: 'e2e_log_marker',
+    logPrefix: 'e2e-log-marker-',
+  });
+  expect(log).not.toContain('/plugins/my-extension/');
+});
+```
+
 ## API Client

 The package provides an API client utility for making authenticated requests to the WooCommerce REST API.
diff --git a/packages/js/e2e-utils-playwright/changelog/wooprd-4105-share-php-debug-log-check b/packages/js/e2e-utils-playwright/changelog/wooprd-4105-share-php-debug-log-check
new file mode 100644
index 00000000000..45decdd0bed
--- /dev/null
+++ b/packages/js/e2e-utils-playwright/changelog/wooprd-4105-share-php-debug-log-check
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Add readPhpDebugLog to verify and read the PHP debug log in Playwright tests.
diff --git a/packages/js/e2e-utils-playwright/src/debug-log.ts b/packages/js/e2e-utils-playwright/src/debug-log.ts
new file mode 100644
index 00000000000..06486bd8083
--- /dev/null
+++ b/packages/js/e2e-utils-playwright/src/debug-log.ts
@@ -0,0 +1,45 @@
+/**
+ * External dependencies
+ */
+import type { APIRequestContext } from '@playwright/test';
+
+/**
+ * Reads the debug log at the site origin after verifying that WordPress wrote to it.
+ *
+ * @param request               - Playwright request context with the store's base URL.
+ * @param marker                - Settings for the site's test-only log marker handler.
+ * @param marker.queryParameter - Query parameter containing the marker value.
+ * @param marker.logPrefix      - Prefix the handler writes immediately before the value.
+ * @return The verified log contents.
+ */
+export async function readPhpDebugLog(
+	request: Pick< APIRequestContext, 'get' >,
+	marker: { queryParameter: string; logPrefix: string }
+): Promise< string > {
+	const value = globalThis.crypto.randomUUID();
+	const markerResponse = await request.get( '/', {
+		params: { [ marker.queryParameter ]: value },
+	} );
+	if ( ! markerResponse.ok() ) {
+		throw new Error(
+			`PHP log marker request failed (HTTP ${ markerResponse.status() }).`
+		);
+	}
+
+	const logResponse = await request.get( '/wp-content/debug.log' );
+	const status = logResponse.status();
+	if ( status !== 200 ) {
+		throw new Error(
+			`Could not read /wp-content/debug.log (HTTP ${ status }).`
+		);
+	}
+
+	const log = await logResponse.text();
+	if ( ! log.includes( `${ marker.logPrefix }${ value }` ) ) {
+		throw new Error(
+			'/wp-content/debug.log did not contain the new marker.'
+		);
+	}
+
+	return log;
+}
diff --git a/packages/js/e2e-utils-playwright/src/index.ts b/packages/js/e2e-utils-playwright/src/index.ts
index 5257f4db52b..1e377cace03 100644
--- a/packages/js/e2e-utils-playwright/src/index.ts
+++ b/packages/js/e2e-utils-playwright/src/index.ts
@@ -1,6 +1,7 @@
 // Re-export all modules
 export * from './cart';
 export * from './checkout';
+export * from './debug-log';
 export * from './editor';
 export * from './order';
 export * from './api-client';
diff --git a/packages/js/e2e-utils-playwright/src/test/debug-log.test.ts b/packages/js/e2e-utils-playwright/src/test/debug-log.test.ts
new file mode 100644
index 00000000000..99eb0e88839
--- /dev/null
+++ b/packages/js/e2e-utils-playwright/src/test/debug-log.test.ts
@@ -0,0 +1,79 @@
+/** @jest-environment node */
+
+/**
+ * External dependencies
+ */
+import type { APIRequestContext } from '@playwright/test';
+
+/**
+ * Internal dependencies
+ */
+import { readPhpDebugLog } from '../debug-log';
+
+describe( 'readPhpDebugLog', () => {
+	const marker = {
+		queryParameter: 'e2e_log_marker',
+		logPrefix: 'e2e-log-marker-',
+	};
+	const get = jest.fn();
+	const request = { get } as Pick< APIRequestContext, 'get' >;
+
+	beforeEach( () => {
+		get.mockReset();
+	} );
+
+	it.each( [
+		marker,
+		{
+			queryParameter: 'acceptance_log_marker',
+			logPrefix: 'acceptance-log-marker-',
+		},
+	] )( 'reads the log written by $queryParameter', async ( logMarker ) => {
+		const value = '4d34912a-1697-419d-9aa1-d4196772d663';
+		jest.spyOn( globalThis.crypto, 'randomUUID' ).mockReturnValueOnce(
+			value
+		);
+		const text = `${ logMarker.logPrefix }${ value }\nPHP Warning: example`;
+		get.mockResolvedValueOnce( { ok: () => true } ).mockResolvedValueOnce( {
+			status: () => 200,
+			text: () => Promise.resolve( text ),
+		} );
+
+		const log = await readPhpDebugLog( request, logMarker );
+		expect( log ).toBe( text );
+		expect( get ).toHaveBeenNthCalledWith( 1, '/', {
+			params: { [ logMarker.queryParameter ]: value },
+		} );
+		expect( get ).toHaveBeenNthCalledWith( 2, '/wp-content/debug.log' );
+	} );
+
+	it( 'stops if WordPress rejects the marker request', async () => {
+		get.mockResolvedValueOnce( { ok: () => false, status: () => 503 } );
+
+		await expect( readPhpDebugLog( request, marker ) ).rejects.toThrow(
+			'PHP log marker request failed (HTTP 503).'
+		);
+		expect( get ).toHaveBeenCalledTimes( 1 );
+	} );
+
+	it( 'fails when the debug log cannot be read', async () => {
+		get.mockResolvedValueOnce( { ok: () => true } ).mockResolvedValueOnce( {
+			status: () => 404,
+		} );
+
+		await expect( readPhpDebugLog( request, marker ) ).rejects.toThrow(
+			'Could not read /wp-content/debug.log (HTTP 404).'
+		);
+	} );
+
+	it( 'rejects a readable log that lacks the fresh marker', async () => {
+		get.mockResolvedValueOnce( { ok: () => true } ).mockResolvedValueOnce( {
+			status: () => 200,
+			text: () => Promise.resolve( 'e2e-log-marker-old\n' ),
+		} );
+
+		await expect( readPhpDebugLog( request, marker ) ).rejects.toThrow(
+			'/wp-content/debug.log did not contain the new marker.'
+		);
+	} );
+} );