pcov/clobber
Clobber PHPUnit 5–7’s Xdebug code coverage driver to use PCOV instead. Install with composer and run vendor/bin/pcov clobber or unclobber (optionally targeting another directory). Useful when upgrading to PHPUnit 8 isn’t feasible.
Installation:
composer require --dev pcov/clobber
This adds the pcov CLI tool to vendor/bin/ and installs the necessary PCOV drivers.
First Use Case: Replace Xdebug with PCOV in your Laravel project’s root:
vendor/bin/pcov clobber
Verify the switch with:
php -m | grep -E 'xdebug|pcov'
(Xdebug should disappear; pcov should appear.)
Where to Look First:
clobber/unclobber syntax.phpunit.xml and CI/CD scripts (e.g., .github/workflows/).src/ClobberCommand.php for edge-case handling (e.g., permission errors).Laravel Test Workflow:
phpunit.xml or composer.json):
<!-- phpunit.xml -->
<php>
<env name="PCOV_ENABLED" value="1"/>
<script type="php"><![CDATA[
putenv('PCOV_ENABLED=1');
shell_exec('vendor/bin/pcov clobber');
]]></script>
</php>
composer.json):
{
"scripts": {
"test": "phpunit && vendor/bin/pcov unclobber"
}
}
CI/CD Pipeline:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install --dev
- run: vendor/bin/pcov clobber
- run: vendor/bin/phpunit --coverage-clover=coverage.xml
- run: vendor/bin/pcov unclobber
- uses: actions/upload-artifact@v3
with:
name: coverage
path: coverage.xml
test:
script:
- composer install --dev
- vendor/bin/pcov clobber
- vendor/bin/phpunit --coverage-text
- vendor/bin/pcov unclobber
Local Development:
# deploy.sh
if [ "$ENV" = "production" ]; then
vendor/bin/pcov clobber
else
vendor/bin/pcov unclobber
fi
Laravel Forge/Envoyer:
pcov clobber during deployments if PCOV is required for coverage reports in staging/production.Parallel Testing:
--parallel flag, ensure PCOV is clobbered before all workers spawn:
vendor/bin/pcov clobber && vendor/bin/phpunit --parallel
Docker/Laravel Sail:
docker-compose.yml services:
services:
laravel.test:
volumes:
- ./:/var/www/html
command: bash -c "composer install && vendor/bin/pcov clobber && php artisan test"
Laravel Mix/Webpack:
laravel-mix with PHPUnit, ensure the pcov binary is available in your build environment:
// webpack.mix.js
mix.setPublicPath('public')
.phpUnit(); // Ensures vendor/bin is in PATH
Permission Errors:
pcov clobber fails with Permission denied on Linux.sudo or adjust file permissions:
sudo chmod -R 775 vendor/bin/pcov
www-data) has write access to /usr/local/etc/php/conf.d/ (common Xdebug config path).Xdebug 3+ Conflicts:
pecl uninstall xdebug && pecl install xdebug-2.9.8
False Coverage Reports:
--coverage-process:
vendor/bin/phpunit --coverage-process-isolated
CI/CD Flakiness:
pcov unclobber may fail if Xdebug configs are corrupted.cp /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug_backup.ini
vendor/bin/pcov clobber
# ... tests ...
vendor/bin/pcov unclobber || cp ~/xdebug_backup.ini /usr/local/etc/php/conf.d/xdebug.ini
Laravel Artisan Conflicts:
php artisan test) may fail if Xdebug is clobbered mid-execution.vendor/bin/pcov unclobber && php artisan test
Verify Clobber Status:
php -i | grep -i "xdebug\|pcov"
pcov
pcov.enabled => On => On
Check PHPUnit Configuration:
Ensure phpunit.xml doesn’t force Xdebug:
<!-- Remove or comment out -->
<php>
<!-- <env name="XDEBUG_CONFIG" value="remote_enable=1"/> -->
</php>
Log Clobber Actions:
Add debug output to src/ClobberCommand.php:
public function handle(): void
{
$this->info('Clobbering Xdebug...');
// ... existing logic ...
$this->info('PCOV enabled. Run `php -m` to verify.');
}
Custom Clobber Paths:
Override the default Xdebug config path in src/ClobberCommand.php:
protected function getXdebugConfigPath(): string
{
return base_path('vendor/xdebug.ini'); // Laravel-specific path
}
Automated Clobbering: Create a Laravel service provider to auto-clobber on boot:
// app/Providers/PcovServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\Process\Process;
class PcovServiceProvider extends ServiceProvider
{
public function boot(): void
{
if ($this->app->environment('testing')) {
$process = new Process(['vendor/bin/pcov', 'clobber']);
$process->run();
}
}
}
Environment-Specific Clobbering:
Use Laravel’s .env to control clobbering:
PCOV_CLOBBER=true
// In a service provider or Artisan command
if (env('PCOV_CLOBBER') === 'true') {
shell_exec('vendor/bin/pcov clobber');
}
Laravel Valet: Clobbering may require restarting Valet:
vendor/bin/pcov clobber && valet restart
Laravel Homestead:
Add clobbering to provision.sh:
echo "Running PCOV clobber..."
cd /var/www && composer require pcov/clobber --dev
vendor/bin/pcov clobber
Laravel Dusk:
Ensure Dusk’s ChromeDriver isn’t affected by PCOV (it typically isn’t, but verify with php -m).
How can I help you explore Laravel packages today?