Skip to content

Commit

Permalink
Merge pull request #84 from MGatner/disable
Browse files Browse the repository at this point in the history
Ability to disable reporting a single test in the slowness report by setting `@slowThreshold 0`
  • Loading branch information
johnkary authored Apr 30, 2021
2 parents 617e3af + 10ffdbd commit eff89f6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ https://github.com/johnkary/phpunit-speedtrap/compare/v3.3.0...v4.0.0
## 4.0 (xxxx-xx-xx)

* New option `stopOnSlow` stops execution upon first slow test. Default: false.
* New annotation option `@slowThreshold 0` disables checks for individual tests.

## 3.3.0 (2020-12-18)

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class SomeTestCase extends PHPUnit\Framework\TestCase
}
```

Setting `@slowThreshold` to `0` will disable threshold reports for that test.

## Disable slowness profiling using an environment variable

SpeedTrapListener profiles for slow tests when enabled in phpunit.xml. But using an environment variable named `PHPUNIT_SPEEDTRAP` can enable or disable the listener.
Expand Down
2 changes: 1 addition & 1 deletion src/SpeedTrapListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function endTestSuite(TestSuite $suite): void
*/
protected function isSlow(int $time, int $slowThreshold): bool
{
return $time >= $slowThreshold;
return $time && $time >= $slowThreshold;
}

/**
Expand Down
17 changes: 15 additions & 2 deletions tests/SomeSlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function testCanSetLowerSlowThreshold()

/**
* This test's runtime would normally be over the suite's threshold, but
* this annotation sets a higher threshold, causing it to be not be
* considered slow and not reported on in the test output.
* this annotation sets a higher threshold causing it not to be
* considered slow and not reported in the test output.
*
* @slowThreshold 50000
*/
Expand All @@ -77,6 +77,19 @@ public function testCanSetHigherSlowThreshold()
$this->assertTrue(true);
}

/**
* This test's runtime would normally be over the suite's threshold, but
* this annotation disables threshold checks causing it not to be
* considered slow and not reported in the test output.
*
* @slowThreshold 0
*/
public function testCanDisableSlowThreshold()
{
$this->extendTime(600);
$this->assertTrue(true);
}

/**
* @param int $ms Number of additional microseconds to execute code
*/
Expand Down

0 comments on commit eff89f6

Please sign in to comment.