diff --git a/CHANGELOG.md b/CHANGELOG.md
index d3c3cc3..c7177f1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,7 +9,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.
## 3.3.0 (2020-12-18)
diff --git a/README.md b/README.md
index 6212032..5495a98 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,7 @@ SpeedTrap also supports these parameters:
* **slowThreshold** - Number of milliseconds when a test is considered "slow" (Default: 500ms)
* **reportLength** - Number of slow tests included in the report (Default: 10 tests)
+* **stopOnSlow** - Stop execution upon first slow test (Default: false)
Each parameter is set in `phpunit.xml`:
@@ -55,6 +56,9 @@ Each parameter is set in `phpunit.xml`:
10
+
+ false
+
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 8e95376..8096084 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -30,6 +30,9 @@
5
+
+ false
+
diff --git a/src/SpeedTrapListener.php b/src/SpeedTrapListener.php
index f34bcd4..c8798db 100644
--- a/src/SpeedTrapListener.php
+++ b/src/SpeedTrapListener.php
@@ -48,6 +48,14 @@ class SpeedTrapListener implements TestListener
*/
protected $reportLength;
+ /**
+ * Whether the test runner should halt running additional tests after
+ * finding a slow test.
+ *
+ * @var bool
+ */
+ protected $stopOnSlow;
+
/**
* Collection of slow tests.
* Keys (string) => Printable label describing the test
@@ -132,6 +140,10 @@ protected function addSlowTest(TestCase $test, int $time)
$label = $this->makeLabel($test);
$this->slow[$label] = $time;
+
+ if ($this->stopOnSlow) {
+ $test->getTestResultObject()->stop();
+ }
}
/**
@@ -224,6 +236,7 @@ protected function loadOptions(array $options)
{
$this->slowThreshold = $options['slowThreshold'] ?? 500;
$this->reportLength = $options['reportLength'] ?? 10;
+ $this->stopOnSlow = $options['stopOnSlow'] ?? false;
}
/**