Skip to content

Commit 23cc3ba

Browse files
committed
Properly configure the php.ini for PCOV.
This ensures that `pcov.initial.files` is set to `10000` and `pcov.directory` is configured dynamically based on the value of `LOCAL_DIR`.
1 parent ea36097 commit 23cc3ba

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎tools/local-env/php-config.ini‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ post_max_size = 1G
55
xdebug.start_with_request=trigger
66
xdebug.discover_client_host=true
77
xdebug.client_host=host.docker.internal
8+
9+
# Pre-sizes the internal file tracking array for the thousands of files under
10+
# `src/` or `build/`, avoiding reallocation churn during test warmup.
11+
#
12+
# The default of 64 is far too low here.
13+
pcov.initial.files=10000

‎tools/local-env/scripts/docker.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ if ( [ 'exec', 'run' ].includes( dockerCommand[0] ) && ! process.stdin.isTTY ) {
2020
dockerCommand.splice( 1, 0, '--no-TTY' );
2121
}
2222

23+
/*
24+
* `pcov.directory` restricts instrumentation to `src/`, so PCOV does not record hits for `vendor/`, `tests/`, or
25+
* WordPress test fixtures that PHPUnit would discard at report time anyway.
26+
*/
27+
if ( process.env.LOCAL_PHP_PCOV === 'true' && dockerCommand.includes( '--coverage-clover' ) ) {
28+
const phpunitIdx = dockerCommand.findIndex( ( arg ) => typeof arg === 'string' && arg.endsWith( 'phpunit' ) );
29+
if ( phpunitIdx !== -1 ) {
30+
const localDir = process.env.LOCAL_DIR || 'src';
31+
dockerCommand.splice(
32+
phpunitIdx,
33+
1,
34+
'php',
35+
'-d',
36+
`pcov.directory=/var/www/${ localDir }`,
37+
dockerCommand[ phpunitIdx ]
38+
);
39+
}
40+
}
41+
2342
// Add a --defaults flag to any db command WP-CLI command. See https://core.trac.wordpress.org/ticket/63876.
2443
if ( dockerCommand.includes( 'cli' ) && dockerCommand.includes( 'db' ) && ! dockerCommand.includes( '--defaults' ) ) {
2544
dockerCommand.push( '--defaults' );

0 commit comments

Comments
 (0)