Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Codecov Laravel Package

testo/codecov

Testo code coverage plugin: collects line and branch coverage during test runs and generates CI-friendly reports (Clover, Cobertura, PHPUnit XML). Supports per-test attribution so tools can map covered lines back to the test that exercised them.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the package in a Testo-based Laravel project:
    composer require --dev testo/codecov
    
  2. Enable the plugin in testo.php:
    return [
        'plugins' => [
            Testo\Codecov\CodecovPlugin::class,
        ],
        'coverage' => [
            'enabled' => true,
            'output' => 'cobertura', // or 'clover', 'xml'
            'format' => 'text', // or 'json', 'xml'
        ],
    ];
    
  3. Run tests with coverage:
    vendor/bin/testo --coverage
    
    Outputs reports to storage/logs/testo/coverage/.

First Use Case

Validate CI pipeline integration:

  • Push a commit and observe coverage reports in GitHub Actions/GitLab CI.
  • Use cobertura format for SonarQube or clover for PHPStorm integration.

Implementation Patterns

Workflows

  1. Local Development:

    • Run tests with coverage in watch mode:
      vendor/bin/testo --coverage --watch
      
    • Use --coverage-format=json for programmatic analysis (e.g., custom scripts).
  2. CI/CD Integration:

    • GitHub Actions Example:
      - name: Test with Coverage
        run: |
          php -dxdebug.mode=coverage vendor/bin/testo --coverage=cobertura
      - name: Upload to SonarQube
        uses: SonarSource/sonarqube-scan-action@master
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
      
  3. Per-Test Attribution:

    • Use coverage data to trace test execution:
      // In a test file
      public function test_user_creation() {
          // ... assertions ...
      }
      
    • Check storage/logs/testo/coverage/coverage.json for test-to-line mappings.

Laravel-Specific Patterns

  1. Database Transactions:

    • Testo’s DatabaseTransactions trait works with coverage, but ensure Xdebug isn’t disabled in .env:
      XDEBUG_MODE=coverage
      
  2. Artisan Commands:

    • Test coverage for commands:
      // In Testo test file
      public function test_command_coverage() {
          $this->artisan('command:test')
               ->assertExitCode(0);
      }
      
  3. Custom Reports:

    • Extend the plugin to generate Laravel-specific reports (e.g., Blade template coverage):
      // app/Providers/TestoServiceProvider.php
      public function boot() {
          Testo\Codecov\CodecovPlugin::extend(function ($plugin) {
              $plugin->addReport('laravel', function () {
                  // Custom logic for Laravel coverage
              });
          });
      }
      

Gotchas and Tips

Pitfalls

  1. Xdebug Configuration:

    • Issue: Coverage reports may be empty if Xdebug isn’t properly configured.
    • Fix: Ensure .phpunit.xdebug.ini or CI env includes:
      xdebug.mode=coverage
      xdebug.start_with_request=yes
      
  2. Inline Test Coverage:

    • Issue: Changelog shows toggling of inline test coverage (e.g., 0.1.3). Assume behavior may change.
    • Workaround: Explicitly configure in testo.php:
      'coverage' => [
          'include_inline_tests' => false, // or true
      ],
      
  3. Performance Overhead:

    • Issue: Xdebug adds ~30-50% runtime to tests.
    • Tip: Run coverage only in CI, not locally. Use --no-coverage for fast feedback:
      vendor/bin/testo --no-coverage
      
  4. Report Paths:

    • Issue: Reports default to storage/logs/testo/coverage/, which may not exist.
    • Fix: Ensure storage/logs/testo/ is writable or configure a custom path:
      'coverage' => [
          'output_dir' => storage_path('app/coverage-reports'),
      ],
      

Debugging

  1. Empty Reports:

    • Check: Verify Xdebug is enabled (php -m | grep xdebug).
    • Debug: Run with verbose output:
      vendor/bin/testo --coverage --verbose
      
  2. Format Mismatches:

    • Issue: SonarQube rejects Cobertura reports.
    • Fix: Validate schema:
      xmllint --schema https://raw.githubusercontent.com/cobertura-coverage/cobertura/master/schema/coverage-04.xsd storage/logs/testo/coverage/cobertura.xml
      
  3. Test Attribution:

    • Tip: Use coverage.json to map tests to lines:
      {
        "tests": {
          "path/to/TestClass.php:test_method": ["file.php:10", "file.php:20"]
        }
      }
      

Extension Points

  1. Custom Drivers:

    • Override coverage collection (e.g., for custom PHP parsers):
      Testo\Codecov\CodecovPlugin::extend(function ($plugin) {
          $plugin->setDriver(new CustomCoverageDriver());
      });
      
  2. Report Filters:

    • Exclude directories (e.g., vendor/, tests/):
      'coverage' => [
          'exclude' => [
              'vendor/',
              'tests/Feature/',
          ],
      ],
      
  3. CI-Specific Logic:

    • Dynamically enable/disable coverage based on env:
      'coverage' => [
          'enabled' => app()->environment('ci'),
      ],
      

Laravel Quirks

  1. Service Container Conflicts:

    • Issue: Testo’s plugin system may clash with Laravel’s service binding.
    • Fix: Boot Testo after Laravel’s providers:
      // config/testo.php
      'bootstrap' => [
          App\Providers\TestoServiceProvider::class,
      ],
      
  2. Artisan Command Testing:

    • Tip: Use --coverage with command tests:
      public function test_command_with_coverage() {
          $this->artisan('command:test', ['--coverage' => true])
               ->expectsOutput('Coverage: 100%')
               ->assertExitCode(0);
      }
      
  3. Pest Migration:

    • Workaround: If migrating from Pest, alias Testo commands in composer.json:
      "scripts": {
          "test": "testo",
          "test:coverage": "testo --coverage"
      }
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky