Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option stopOnSlow halts execution upon first slow test #82

Merged
merged 1 commit into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:

Expand All @@ -55,6 +56,9 @@ Each parameter is set in `phpunit.xml`:
<element key="reportLength">
<integer>10</integer>
</element>
<element key="stopOnSlow">
<boolean>false</boolean>
</element>
</array>
</arguments>
</listener>
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<element key="reportLength">
<integer>5</integer>
</element>
<element key="stopOnSlow">
<boolean>false</boolean>
</element>
</array>
</arguments>
</listener>
Expand Down
13 changes: 13 additions & 0 deletions src/SpeedTrapListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}

/**
Expand Down Expand Up @@ -224,6 +236,7 @@ protected function loadOptions(array $options)
{
$this->slowThreshold = $options['slowThreshold'] ?? 500;
$this->reportLength = $options['reportLength'] ?? 10;
$this->stopOnSlow = $options['stopOnSlow'] ?? false;
}

/**
Expand Down