johnkary / phpunit-speedtrap

Reports on slow-running tests in your PHPUnit test suite
MIT License
783 stars 62 forks source link

Environment variable PHPUNIT_SPEEDTRAP="disabled" can disable profiling #66

Closed johnkary closed 4 years ago

johnkary commented 4 years ago

This PR allows using an environment variable PHPUNIT_SPEEDTRAP to disable slowness profiling for each environment. Setting the value "disabled" will disable slowness profiling and not display the slowness report in the PHPUnit test suite output. The README contains more information.

Disable for just this run

$ PHPUNIT_SPEEDTRAP="disabled" ./vendor/bin/phpunit

Disabled by default, enable for just this run

phpunit.xml can also be configured to disable profiling by default with PHPUNIT_SPEEDTRAP="disabled". A developer can enable slowness profiling locally or one time only by setting PHPUNIT_SPEEDTRAP="enabled" using any environment variable mechanism in PHP.

Disable profiling in phpunit.xml by default

<phpunit bootstrap="vendor/autoload.php">
...
    <php>
        <env name="PHPUNIT_SPEEDTRAP" value="disabled" />
    </php>

    <listeners>
        <listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
    </listeners>
</phpunit>

Enable profiling for just this run

$ PHPUNIT_SPEEDTRAP="enabled" ./vendor/bin/phpunit

How do I set environment variables?

PHP supports many ways to set environment variables, making this a flexible feature to match any project configuration.

Some projects use vlucas/phpdotenv to manage their environment variables.

Associated Issues