|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Install PCOV extension in wp-env Docker container for faster PHP coverage. |
| 4 | +# This script is called by wp-env lifecycleScripts.afterStart. |
| 5 | +# |
| 6 | +# PCOV is ~5-10x faster than Xdebug for coverage collection. |
| 7 | + |
| 8 | +set -e |
| 9 | + |
| 10 | +# Only install if PHP_COVERAGE_ENABLED is set |
| 11 | +if [ -z "$PHP_COVERAGE_ENABLED" ]; then |
| 12 | + echo "PHP_COVERAGE_ENABLED not set, skipping PCOV installation." |
| 13 | + exit 0 |
| 14 | +fi |
| 15 | + |
| 16 | +echo "Installing PCOV for PHP coverage..." |
| 17 | + |
| 18 | +# Get the wp-env install path |
| 19 | +WP_ENV_PATH=$(wp-env install-path) |
| 20 | +cd "$WP_ENV_PATH" |
| 21 | + |
| 22 | +# Check if PCOV is already installed |
| 23 | +if docker compose exec -T tests-wordpress php -m 2>/dev/null | grep -q "^pcov$"; then |
| 24 | + echo "PCOV already installed." |
| 25 | + exit 0 |
| 26 | +fi |
| 27 | + |
| 28 | +echo "Installing PCOV extension..." |
| 29 | + |
| 30 | +# Install PCOV using pecl (run as root) |
| 31 | +docker compose exec -T -u root tests-wordpress bash -c ' |
| 32 | + # Install dependencies for pecl |
| 33 | + apt-get update -qq && apt-get install -qq -y autoconf gcc make > /dev/null 2>&1 || true |
| 34 | +
|
| 35 | + # Install PCOV |
| 36 | + pecl install pcov > /dev/null 2>&1 |
| 37 | +
|
| 38 | + # Enable PCOV |
| 39 | + docker-php-ext-enable pcov |
| 40 | +
|
| 41 | + # Configure PCOV |
| 42 | + echo "pcov.enabled=1" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini |
| 43 | + echo "pcov.directory=/var/www/html/wp-content/plugins/secure-custom-fields" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini |
| 44 | +
|
| 45 | + # Disable Xdebug if enabled (they conflict) |
| 46 | + if [ -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini ]; then |
| 47 | + mv /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini.disabled || true |
| 48 | + fi |
| 49 | +' |
| 50 | + |
| 51 | +# Restart Apache to load the new extension |
| 52 | +docker compose exec -T -u root tests-wordpress service apache2 reload > /dev/null 2>&1 || true |
| 53 | + |
| 54 | +echo "PCOV installed successfully." |
0 commit comments