Skip to content

Commit cf1284b

Browse files
authored
Merge pull request #83 from johnkary/extension-upgrade
Use PHPUnit Extension system instead of Listener
2 parents f1cc189 + 372da42 commit cf1284b

File tree

9 files changed

+129
-89
lines changed

9 files changed

+129
-89
lines changed

.github/workflows/integrate.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ jobs:
1919

2020
matrix:
2121
include:
22-
- php-version: "7.1"
23-
phpunit-version: "7.*"
24-
25-
- php-version: "7.2"
26-
phpunit-version: "7.*"
27-
2822
- php-version: "7.2"
2923
phpunit-version: "8.*"
3024

@@ -46,6 +40,12 @@ jobs:
4640
- php-version: "8.0"
4741
phpunit-version: "9.*"
4842

43+
- php-version: "8.1"
44+
phpunit-version: "8.*"
45+
46+
- php-version: "8.1"
47+
phpunit-version: "9.*"
48+
4949
steps:
5050
- name: "Checkout"
5151
uses: "actions/checkout@v2"

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ CHANGELOG
44
View diff for a specific commit:
55
https://github.com/johnkary/phpunit-speedtrap/commit/XXX where XXX is the commit hash
66

7+
View diff between two versions:
8+
https://github.com/johnkary/phpunit-speedtrap/compare/v4.0.0...v5.0.0
9+
10+
## 5.0 (xxxx-xx-xx)
11+
12+
Version 5.0 is the largest change since v1.0. It now uses PHPUnit's Extension
13+
and Hook systems, which have more restrictions on what an Extension is allowed
14+
to do.
15+
16+
Changes are required if you have extended SpeedTrapListener. See
17+
[UPGRADE.md](UPGRADE.md) for upgrading your subclass to support 5.0.
18+
19+
* SpeedTrap now requires PHPUnit 8+ and PHP 7.2+,
20+
* Moved namespace from `JohnKary\PHPUnit\Listener\SpeedTrapListener` to `JohnKary\PHPUnit\Extension\SpeedTrap`
21+
* `phpunit.xml` requires registering using <extension> element instead of <listener> element. See README.
22+
* Removed option `stopOnSlow` because Extensions can no longer manipulate the Test Runner
23+
724
## 4.0.1 (2022-10-16)
825

926
* README documents working with Symfony Framework `simple-phpunit`

README.md

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SpeedTrap reports on slow-running PHPUnit tests right in the console.
66

77
Many factors affect test execution time. A test not properly isolated from variable latency (database, network, etc.) and even basic load on the test machine will cause test execution times to fluctuate.
88

9-
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.
9+
SpeedTrap helps **identify slow tests** but cannot explain **why** those tests are slow. Consider using [Blackfire.io](https://blackfire.io) to profile the test suite to specifically identify slow code.
1010

1111
![Screenshot of terminal using SpeedTrap](https://i.imgur.com/xSpWL4Z.png)
1212

@@ -20,13 +20,13 @@ SpeedTrap is installed using [Composer](http://getcomposer.org). Add it as a `re
2020
## Usage
2121

2222
Enable with all defaults by adding the following code to your project's `phpunit.xml` file:
23-
23+
2424
```xml
2525
<phpunit bootstrap="vendor/autoload.php">
2626
...
27-
<listeners>
28-
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
29-
</listeners>
27+
<extensions>
28+
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
29+
</extensions>
3030
</phpunit>
3131
```
3232

@@ -38,16 +38,15 @@ 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). Activate by setting "true".
4241

4342
Each parameter is set in `phpunit.xml`:
4443

4544
```xml
4645
<phpunit bootstrap="vendor/autoload.php">
4746
<!-- ... other suite configuration here ... -->
4847

49-
<listeners>
50-
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener">
48+
<extensions>
49+
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap">
5150
<arguments>
5251
<array>
5352
<element key="slowThreshold">
@@ -56,13 +55,10 @@ Each parameter is set in `phpunit.xml`:
5655
<element key="reportLength">
5756
<integer>10</integer>
5857
</element>
59-
<element key="stopOnSlow">
60-
<boolean>false</boolean>
61-
</element>
6258
</array>
6359
</arguments>
64-
</listener>
65-
</listeners>
60+
</extension>
61+
</extensions>
6662
</phpunit>
6763
```
6864

@@ -89,15 +85,15 @@ Setting `@slowThreshold 0` will never report that test as slow.
8985

9086
## Disable slowness profiling using an environment variable
9187

92-
SpeedTrapListener profiles for slow tests when enabled in phpunit.xml. But using an environment variable named `PHPUNIT_SPEEDTRAP` can enable or disable the listener.
88+
SpeedTrap profiles for slow tests when enabled in phpunit.xml. But using an environment variable named `PHPUNIT_SPEEDTRAP` can enable or disable the extension:
9389

9490
$ PHPUNIT_SPEEDTRAP="disabled" ./vendor/bin/phpunit
9591

9692
#### Use case: Disable profiling in development, but profile with Travis CI
9793

9894
Travis CI is popular for running tests in the cloud after pushing new code to a repository.
9995

100-
Step 1) Enable SpeedTrapListener in phpunit.xml, but set `PHPUNIT_SPEEDTRAP="disabled"` to disable profiling when running tests.
96+
Step 1) Enable SpeedTrap in phpunit.xml, but set `PHPUNIT_SPEEDTRAP="disabled"` to disable profiling when running tests.
10197

10298
```xml
10399
<phpunit bootstrap="vendor/autoload.php">
@@ -106,9 +102,9 @@ Step 1) Enable SpeedTrapListener in phpunit.xml, but set `PHPUNIT_SPEEDTRAP="dis
106102
<env name="PHPUNIT_SPEEDTRAP" value="disabled" />
107103
</php>
108104

109-
<listeners>
110-
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
111-
</listeners>
105+
<extensions>
106+
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
107+
</extensions>
112108
</phpunit>
113109
```
114110

@@ -130,14 +126,14 @@ Step 3) View the Travis CI build output and read the slowness report printed in
130126
131127
#### Use case: Enable profiling in development, but disable with Travis CI
132128
133-
Step 1) Enable SpeedTrapListener in phpunit.xml. The slowness report will output during all test suite executions.
129+
Step 1) Enable SpeedTrap in phpunit.xml. The slowness report will output during all test suite executions.
134130
135131
```xml
136132
<phpunit bootstrap="vendor/autoload.php">
137133
...
138-
<listeners>
139-
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
140-
</listeners>
134+
<extensions>
135+
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
136+
</extensions>
141137
</phpunit>
142138
```
143139

@@ -155,11 +151,11 @@ env:
155151
156152
Step 3) View the Travis CI build output and confirm the slowness report is not printed in the console.
157153
158-
#### Use case: Only enable SpeedTrapListener on demand via command-line
154+
#### Use case: Only enable SpeedTrap on demand via command-line
159155
160156
Useful when you only want to profile slow tests once in a while.
161157
162-
Step 1) Setup phpunit.xml to enable SpeedTrapListener, but disable slowness profiling by setting `PHPUNIT_SPEEDTRAP="disabled"` like this:
158+
Step 1) Setup phpunit.xml to enable SpeedTrap, but disable slowness profiling by setting `PHPUNIT_SPEEDTRAP="disabled"` like this:
163159

164160
```xml
165161
<phpunit bootstrap="vendor/autoload.php">
@@ -168,9 +164,9 @@ Step 1) Setup phpunit.xml to enable SpeedTrapListener, but disable slowness prof
168164
<env name="PHPUNIT_SPEEDTRAP" value="disabled" />
169165
</php>
170166
171-
<listeners>
172-
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
173-
</listeners>
167+
<extensions>
168+
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
169+
</extensions>
174170
</phpunit>
175171
```
176172

@@ -195,9 +191,12 @@ phpunit.xml.dist
195191
<env name="SYMFONY_PHPUNIT_REQUIRE" value="johnkary/phpunit-speedtrap:^4"/>
196192
<env name="SYMFONY_PHPUNIT_VERSION" value="9"/>
197193
</php>
194+
195+
<extensions>
196+
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
197+
</extensions>
198198
</phpunit>
199199
```
200-
(add the listener as described above)
201200

202201
Using the above example, running `vendor/bin/simple-phpunit` will now install the latest PHPUnit 9 and require the latest phpunit-speedtrap v4.
203202

UPGRADE.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
UPGRADE FROM 4.x to 5.0
2+
=======================
3+
4+
This library's v4 core file `JohnKary\PHPUnit\Listener\SpeedTrapListener` has been
5+
replaced by `JohnKary\PHPUnit\Extension\SpeedTrap` in v5. This change reflects
6+
switching from PHPUnit's Listener system to its Hook system.
7+
8+
The `SpeedTrap` Extension must be registered differently in `phpunit.xml`:
9+
10+
```xml
11+
<phpunit bootstrap="vendor/autoload.php">
12+
...
13+
- <listeners>
14+
- <listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
15+
- </listeners>
16+
+ <extensions>
17+
+ <extension class="JohnKary\PHPUnit\Extension\SpeedTrap">
18+
+ <arguments>
19+
+ <array>
20+
+ <element key="slowThreshold">
21+
+ <integer>500</integer>
22+
+ </element>
23+
+ <element key="reportLength">
24+
+ <integer>5</integer>
25+
+ </element>
26+
+ </array>
27+
+ </arguments>
28+
+ </extension>
29+
+ </extensions>
30+
</phpunit>
31+
```
32+
33+
If you have extended the old `JohnKary\PHPUnit\Listener\SpeedTrapListener`, you
34+
must extend the new `JohnKary\PHPUnit\Extension\SpeedTrap`. There are various
35+
method name changes that may affect your custom subclass. See [PR #83](https://github.com/johnkary/phpunit-speedtrap/pull/83)
36+
for how the new class has changed.
37+
138
UPGRADE FROM 3.x to 4.0
239
=======================
340

composer.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"description": "Find and report on slow tests in your PHPUnit test suite",
55
"keywords": [
66
"PHPUnit",
7+
"extension",
8+
"hook",
9+
"listener",
710
"slow",
811
"profile"
912
],
@@ -16,22 +19,22 @@
1619
}
1720
],
1821
"require": {
19-
"php": ">=7.1",
20-
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0"
22+
"php": ">=7.2",
23+
"phpunit/phpunit": "^8.0 || ^9.0"
2124
},
2225
"extra": {
2326
"branch-alias": {
24-
"dev-master": "4.0-dev"
27+
"dev-master": "5.0-dev"
2528
}
2629
},
2730
"autoload": {
2831
"psr-4": {
29-
"JohnKary\\PHPUnit\\Listener\\": "src/"
32+
"JohnKary\\PHPUnit\\Extension\\": "src/"
3033
}
3134
},
3235
"autoload-dev": {
3336
"psr-4": {
34-
"JohnKary\\PHPUnit\\Listener\\Tests\\": "tests/"
37+
"JohnKary\\PHPUnit\\Extension\\Tests\\": "tests/"
3538
}
3639
}
3740
}

phpunit.xml.dist

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
</testsuite>
1414
</testsuites>
1515

16-
<listeners>
17-
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener">
16+
<extensions>
17+
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap">
1818
<arguments>
1919
<array>
2020
<element key="slowThreshold">
@@ -23,13 +23,10 @@
2323
<element key="reportLength">
2424
<integer>5</integer>
2525
</element>
26-
<element key="stopOnSlow">
27-
<boolean>false</boolean>
28-
</element>
2926
</array>
3027
</arguments>
31-
</listener>
32-
</listeners>
28+
</extension>
29+
</extensions>
3330

3431
<filter>
3532
<whitelist>

0 commit comments

Comments
 (0)