RSS Amplifier

susi.dev · Sep 27, 2020

TYPO3 test coverage in under 2 minutes with PhpStorm + phpdbg

0
Sign in to vote or save

Susanne Moog · susi.dev

Skip to content

susi.dev

Published on

Authors

phpdbg can generate PHPUnit coverage much faster than Xdebug. Here’s how to use it in TYPO3 projects — directly from PhpStorm or via CLI — and get coverage in under a couple of minutes on typical setups.

Why phpdbg for coverage?

  • No need to enable Xdebug (keeps runtime fast)
  • Good performance for coverage generation
  • Works well locally and in CI

Prerequisites

  • phpdbg available in your PHP installation (most distributions package it alongside PHP)
  • A working phpunit.xml(.dist)

Check availability:

phpdbg -h

If not found, install/enable phpdbg for your platform (e.g., apt-get install php7.4-phpdbg or the equivalent for your PHP version).

Run coverage via CLI

From your project root:

phpdbg -qrr ./vendor/bin/phpunit \
  --configuration phpunit.xml \
  --coverage-html build/coverage \
  --coverage-clover build/coverage/clover.xml

Notes:

  • -qrr runs phpunit inside phpdbg.
  • Adjust paths as needed. build/coverage will contain the HTML report.

PhpStorm configuration (use phpdbg)

  1. Settings → PHP → Test Frameworks → Add PHPUnit by (Remote) Interpreter
    • Interpreter: your local/remote PHP used for the project (Docker/DDEV etc.)
    • Autoloader: vendor/autoload.php
    • Configuration: phpunit.xml(.dist)
  2. Run/Debug Configurations → + → PHPUnit
    • Choose your scope (directory, class, method)
    • In "Interpreter Options" add: -d xdebug.mode=off (optional)
    • In "Custom runner" or "Command line" ensure phpdbg is used if your interpreter supports it. If PhpStorm doesn’t expose a toggle, configure your interpreter to point at phpdbg or create a helper script.

Alternative: Create a PhpStorm "PHP Script" configuration that calls:

phpdbg -qrr ./vendor/bin/phpunit --configuration phpunit.xml --coverage-html build/coverage

Then run it like any other configuration; PhpStorm will open the HTML report if you set it up as an artifact.

With DDEV/Docker

If you use DDEV (or Docker), run phpdbg inside the container:

# DDEV
ddev exec phpdbg -qrr ./vendor/bin/phpunit --configuration phpunit.xml --coverage-html build/coverage

# Generic Docker (example container name "web")
docker exec -it web phpdbg -qrr /var/www/html/vendor/bin/phpunit --configuration /var/www/html/phpunit.xml --coverage-html /var/www/html/build/coverage

Map the build/coverage directory to your host to open reports in the browser.

Tips and troubleshooting

  • Disable Xdebug for speed: -d xdebug.mode=off or turn it off in your environment.
  • Ensure pcov.enabled=0 or other coverage engines are disabled to avoid conflicts.
  • Large test suites: generate only HTML or only Clover to reduce I/O time.
  • In PhpStorm, if you don’t see the built‑in coverage view for phpdbg: open the HTML report from build/coverage/index.html, or configure Clover report in a compatible plugin/CI.

Example composer scripts

Add convenience scripts to composer.json:

{
  "scripts": {
    "test:coverage": "phpdbg -qrr ./vendor/bin/phpunit --configuration phpunit.xml --coverage-html build/coverage --coverage-clover build/coverage/clover.xml"
  }
}

Run with:

composer run test:coverage
# or with DDEV
ddev composer test:coverage

That’s it — use phpdbg to get quick code coverage locally and in CI without the overhead of Xdebug.

Read the original on susi.dev

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.