Installation
composer require bwen/clover2lcov-bundle
Register the bundle in config/bundles.php:
return [
// ...
Bwen\Clover2LcovBundle\Clover2LcovBundle::class => ['all' => true],
];
First Use Case
Run the command to convert a clover.xml file to lcov.info:
php bin/console convert:clover2lcov path/to/clover.xml path/to/lcov.info
genhtml lcov.info (requires lcov CLI tools).php bin/console list → convert:clover2lcov.config/packages/bwen_clover2lcov.yaml (if created).src/Command/ConvertClover2LcovCommand.php for customization hooks.CI/CD Integration
Add to .github/workflows/coverage.yml:
- name: Convert Clover to Lcov
run: php bin/console convert:clover2lcov build/clover.xml build/lcov.info
- name: Upload to Codecov
uses: codecov/codecov-action@v3
with:
file: build/lcov.info
Laravel-Specific Usage
Artisan::call() in a custom command or service:
Artisan::call('convert:clover2lcov', [
'input' => storage_path('logs/clover.xml'),
'output' => storage_path('logs/lcov.info'),
]);
Pre-Processing
Chain with other tools (e.g., phpunit --coverage-clover=clover.xml):
phpunit --coverage-clover=clover.xml && \
php bin/console convert:clover2lcov clover.xml lcov.info
CLOVER_INPUT_PATH/CLOVER_OUTPUT_PATH in .env.console.command events (see Gotchas).File Permissions Ensure PHP process has write access to the output path. Debug with:
chmod -R 777 build/ # Temporary fix (avoid in production)
Clover XML Validity Invalid XML (e.g., malformed tags) crashes the command. Validate with:
xmllint --noout clover.xml
Lcov Toolchain
genhtml requires lcov and graphviz. Install via:
sudo apt-get install lcov graphviz # Debian/Ubuntu
--verbose to the command for debug output.Bwen\Clover2LcovBundle\Clover2LcovBundle::DEBUG in config/bundles.php for trace logs.Custom Conversion Logic
Override the command class (e.g., app/Command/CustomConvertCommand) and extend:
use Bwen\Clover2LcovBundle\Command\ConvertClover2LcovCommand;
class CustomConvertCommand extends ConvertClover2LcovCommand {
protected function execute(InputInterface $input, OutputInterface $output) {
// Pre/post-processing logic
parent::execute($input, $output);
}
}
Event Dispatching
Listen for console.command.clover2lcov events to hook into conversion:
// src/EventListener/CloverListener.php
public function onCloverConvert(CloverConvertEvent $event) {
$event->setOutputPath($event->getOutputPath() . '.custom');
}
Configuration
Override default paths in config/packages/bwen_clover2lcov.yaml:
bwen_clover2lcov:
input_path: '%kernel.project_dir%/var/clover.xml'
output_path: '%kernel.project_dir%/var/lcov.info'
How can I help you explore Laravel packages today?