codeception/c3
C3 is Codeception’s remote code coverage helper for PHP apps. It collects coverage from web/functional tests by instrumenting your entry point and forwarding results back to the test runner, making it easy to measure coverage on remote servers and CI.
Installation Add the package via Composer in your Laravel project:
composer require --dev codeception/c3
Ensure codeception/codeception is also installed (required dependency).
Configuration
Update your codeception.yml to include the C3 module:
modules:
enabled:
- C3
Configure C3 in .codeception.dist.yml (or directly in codeception.yml):
C3:
url: 'https://coverage.example.com' # Your remote coverage server
token: 'your_api_token' # API token for authentication
project: 'your_project_name' # Project identifier
First Use Case Run tests with coverage upload:
./vendor/bin/codecept run --coverage --coverage-xml --coverage-c3
Verify coverage data appears on your remote server.
Local Testing with Remote Upload
codecept run with --coverage-c3 to upload coverage after each test run.- name: Run tests with coverage
run: ./vendor/bin/codecept run --coverage --coverage-c3
Conditional Uploads
C3:
enabled: ${ENV:CI} # Only upload in CI
Parallel Testing
codecept run -p), ensure unique project or token per worker to avoid conflicts.Integration with Laravel
phpunit.xml to trigger Codeception:
<phpunit>
<listeners>
<listener class="Codeception\Codecept\PHPUnit\Listener" file="vendor/codeception/codeception/codecept.php"/>
</listeners>
</phpunit>
php artisan codecept run --coverage-c3
Custom Coverage Filters
Exclude Laravel-specific paths (e.g., vendor/, bootstrap/) in codeception.yml:
C3:
exclude:
- vendor/
- bootstrap/*
Branch/Tag-Based Projects
Dynamically set project in codeception.yml:
C3:
project: 'laravel-${GIT_BRANCH}' # Use CI env vars
Post-Test Hooks
Use Codeception’s after hooks to validate coverage before upload:
// tests/_support/Helper/Acceptance.php
public function _after(AcceptanceTester $I) {
if ($I->grabService('C3')->getCoverage() < 80) {
throw new \Exception("Coverage too low!");
}
}
Authentication Failures
403 Forbidden errors if token is missing/invalid.Coverage Data Mismatches
--coverage-xml is used alongside --coverage-c3 to generate consistent data.CI Environment Conflicts
.env.testing or CI-specific config:
C3:
url: ${COVERAGE_SERVER_URL}
token: ${COVERAGE_TOKEN}
Rate Limits
Enable Verbose Logging
Run with -vvv to debug C3 interactions:
./vendor/bin/codecept run --coverage-c3 -vvv
Check Server Status Verify your C3 server is reachable:
curl -v https://coverage.example.com/api/status
Local Testing Without Upload Disable uploads for local runs:
C3:
enabled: false
Custom Upload Logic
Extend the C3 module by overriding uploadCoverage() in a custom module:
class CustomC3 extends \Codeception\Module\C3 {
public function uploadCoverage() {
// Custom logic (e.g., pre-process data)
parent::uploadCoverage();
}
}
Webhook Triggers Use C3’s API to trigger builds on coverage updates (e.g., via GitHub Actions webhooks).
Dashboard Integration Embed C3’s coverage reports in Laravel’s admin panel using its API:
$coverage = Http::get('https://coverage.example.com/api/coverage', [
'token' => config('services.c3.token'),
]);
url ends with / (e.g., https://example.com/).laravel-auth).How can I help you explore Laravel packages today?