Skip to content

Commit eff89f6

Browse files
authored
Merge pull request #84 from MGatner/disable
Ability to disable reporting a single test in the slowness report by setting `@slowThreshold 0`
2 parents 617e3af + 10ffdbd commit eff89f6

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ https://github.com/johnkary/phpunit-speedtrap/compare/v3.3.0...v4.0.0
1010
## 4.0 (xxxx-xx-xx)
1111

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

1415
## 3.3.0 (2020-12-18)
1516

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class SomeTestCase extends PHPUnit\Framework\TestCase
8585
}
8686
```
8787

88+
Setting `@slowThreshold` to `0` will disable threshold reports for that test.
89+
8890
## Disable slowness profiling using an environment variable
8991

9092
SpeedTrapListener profiles for slow tests when enabled in phpunit.xml. But using an environment variable named `PHPUNIT_SPEEDTRAP` can enable or disable the listener.

src/SpeedTrapListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function endTestSuite(TestSuite $suite): void
129129
*/
130130
protected function isSlow(int $time, int $slowThreshold): bool
131131
{
132-
return $time >= $slowThreshold;
132+
return $time && $time >= $slowThreshold;
133133
}
134134

135135
/**

tests/SomeSlowTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public function testCanSetLowerSlowThreshold()
6666

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

80+
/**
81+
* This test's runtime would normally be over the suite's threshold, but
82+
* this annotation disables threshold checks causing it not to be
83+
* considered slow and not reported in the test output.
84+
*
85+
* @slowThreshold 0
86+
*/
87+
public function testCanDisableSlowThreshold()
88+
{
89+
$this->extendTime(600);
90+
$this->assertTrue(true);
91+
}
92+
8093
/**
8194
* @param int $ms Number of additional microseconds to execute code
8295
*/

0 commit comments

Comments
 (0)