johnkary / phpunit-speedtrap

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

Only output slowness report when explicitly enabled #63

Closed johnkary closed 3 years ago

johnkary commented 5 years ago

PHPUnit may be configured with runtime options that alter its output or generated reports, such as --coverage-html or --log-junit or --testdox-html

Currently the slowness report is output on every test suite execution when SpeedTrapListener is enabled in phpunit.xml. This may not be desired when running PHPUnit with other options. For example, generating code coverage via --coverage-html is an opt-in runtime option. SpeedTrap should behave similarly.

Instead, the slowness report should only output when at least one of the following is true:

  1. Providing runtime command-line argument: --speedtrap
  2. PHP environment variable PHPUNIT_SPEEDTRAP has a string value of "enabled"

PHP environment variables can be set in php.ini or any method supported by PHP.

PHP environment variables can also be set using phpunit.xml:

<phpunit>
    <php>
        <env name="PHPUNIT_SPEEDTRAP" value="enabled" />
    </php>
</phpunit>

Feedback requested

  1. Are there any other ways we should support opt-in slowness reporting?
  2. What do you think of the name --speedtrap for runtime option? I'm not sure if/how this option's presence can be detected by the listener, but it can probably be done.
  3. What do you think of the name PHPUNIT_SPEEDTRAP for the environment variable? This name scopes it into a fake namespace (PHPUNIT) and specific to this library (SPEEDTRAP).
  4. Suggestions for PHPUNIT_SPEEDTRAP variable value to declare the listener should be enabled? I proposed string "enabled" because: 1) environment variables should always assume to be strings; 2) using a word prevents accidental type casting (i.e. "true" could become a boolean, "1" could be come an int or boolean; 3) the word definition of "enabled" declares exactly its effect on the listener behavior.
MarkVaughn commented 3 years ago

I'm confused as why this wasn't working, and I saw it isn't part of 3.2 release. was that an oversight? https://github.com/johnkary/phpunit-speedtrap/compare/v3.2.0...master Thanks for the great work!

johnkary commented 3 years ago

Hi @MarkVaughn, Sorry for the confusion. This ticket should have been closed when #66 was merged. Feature #66 is complete and now part of tagged version v3.3.0.

I originally thought this feature would be part of a v4.0 release. When you left that comment, it was merged to master, but not yet tagged on a release.

v4.0 will still happen and update to using PHPUnit's hooks system via #67.