Skip to content

Commit 095e461

Browse files
authored
Merge pull request #81 from johnkary/support-filter-option
Reformat slow test case output for compatibility with PHPUnit --filter option
2 parents e90bad2 + 608a065 commit 095e461

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Many factors affect test execution time. A test not properly isolated from varia
88

99
SpeedTrap helps **identify slow tests** but cannot explain **why** those tests are slow. For that consider using [Blackfire.io](https://blackfire.io) to profile the test suite, or another PHPUnit listener [PHPUnit\_Listener\_XHProf](https://github.com/sebastianbergmann/phpunit-testlistener-xhprof), to specifically identify slow code.
1010

11-
![Screenshot of terminal using SpeedTrap](http://i.imgur.com/Zr34giR.png)
11+
![Screenshot of terminal using SpeedTrap](https://i.imgur.com/xSpWL4Z.png)
1212

1313
## Installation
1414

UPGRADE.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
UPGRADE FROM 3.x to 4.0
2+
=======================
3+
4+
### Slowness report changes formatting of slow class names
5+
6+
Prior to 4.0 the slowness report displayed the qualified class name in a
7+
human-readable format as normally seen in code:
8+
9+
1. 800ms to run JohnKary\PHPUnit\Listener\Tests\SomeSlowTest:testWithDataProvider with data set "Rock"
10+
11+
After 4.0 the slowness report displays class names in a format ready to be
12+
used with PHPUnit's [--filter option](https://phpunit.readthedocs.io/en/9.5/textui.html?highlight=filter)
13+
by adding slashes to the namespace delimiter and adding a colon between the
14+
class and method name:
15+
16+
1. 800ms to run JohnKary\\PHPUnit\\Listener\\Tests\\SomeSlowTest::testWithDataProvider with data set "Rock"
17+
18+
An individual slow test case can now be re-run by copying and pasting the output
19+
into a new command:
20+
21+
vendor/bin/phpunit --filter 'JohnKary\\PHPUnit\\Listener\\Tests\\SomeSlowTest::testWithDataProvider with data set "Rock"'
22+
23+
Note that PHPUnit uses single quotes for the `--filter` option value. See the
24+
[--filter option documentation](https://phpunit.readthedocs.io/en/9.5/textui.html?highlight=filter)
25+
for all supported matching patterns.
26+
127
UPGRADE FROM 2.x to 3.0
228
=======================
329

src/SpeedTrapListener.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,14 @@ protected function toMilliseconds(float $time): int
151151
}
152152

153153
/**
154-
* Label describing a test.
154+
* Label describing a slow test case. Formatted to support copy/paste with
155+
* PHPUnit's --filter CLI option:
156+
*
157+
* vendor/bin/phpunit --filter 'JohnKary\\PHPUnit\\Listener\\Tests\\SomeSlowTest::testWithDataProvider with data set "Rock"'
155158
*/
156159
protected function makeLabel(TestCase $test): string
157160
{
158-
return sprintf('%s::%s', get_class($test), $test->getName());
161+
return sprintf('%s::%s', addslashes(get_class($test)), $test->getName());
159162
}
160163

161164
/**

0 commit comments

Comments
 (0)