Skip to content

Commit 78f04c0

Browse files
committed
Add option stopOnSlow for halting execution upon first slow test
1 parent e90bad2 commit 78f04c0

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ https://github.com/johnkary/phpunit-speedtrap/compare/v3.3.0...v4.0.0
99

1010
## 4.0 (xxxx-xx-xx)
1111

12-
12+
* New option `stopOnSlow` stops execution upon first slow test. Default: false.
1313

1414
## 3.3.0 (2020-12-18)
1515

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ SpeedTrap also supports these parameters:
3838

3939
* **slowThreshold** - Number of milliseconds when a test is considered "slow" (Default: 500ms)
4040
* **reportLength** - Number of slow tests included in the report (Default: 10 tests)
41+
* **stopOnSlow** - Stop execution upon first slow test (Default: false)
4142

4243
Each parameter is set in `phpunit.xml`:
4344

@@ -55,6 +56,9 @@ Each parameter is set in `phpunit.xml`:
5556
<element key="reportLength">
5657
<integer>10</integer>
5758
</element>
59+
<element key="stopOnSlow">
60+
<boolean>false</boolean>
61+
</element>
5862
</array>
5963
</arguments>
6064
</listener>

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<element key="reportLength">
3131
<integer>5</integer>
3232
</element>
33+
<element key="stopOnSlow">
34+
<boolean>false</boolean>
35+
</element>
3336
</array>
3437
</arguments>
3538
</listener>

src/SpeedTrapListener.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ class SpeedTrapListener implements TestListener
4848
*/
4949
protected $reportLength;
5050

51+
/**
52+
* Whether the test runner should halt running additional tests after
53+
* finding a slow test.
54+
*
55+
* @var bool
56+
*/
57+
protected $stopOnSlow;
58+
5159
/**
5260
* Collection of slow tests.
5361
* Keys (string) => Printable label describing the test
@@ -132,6 +140,10 @@ protected function addSlowTest(TestCase $test, int $time)
132140
$label = $this->makeLabel($test);
133141

134142
$this->slow[$label] = $time;
143+
144+
if ($this->stopOnSlow) {
145+
$test->getTestResultObject()->stop();
146+
}
135147
}
136148

137149
/**
@@ -224,6 +236,7 @@ protected function loadOptions(array $options)
224236
{
225237
$this->slowThreshold = $options['slowThreshold'] ?? 500;
226238
$this->reportLength = $options['reportLength'] ?? 10;
239+
$this->stopOnSlow = $options['stopOnSlow'] ?? false;
227240
}
228241

229242
/**

0 commit comments

Comments
 (0)