Skip to content

Commit 00e07ed

Browse files
committed
Enhancement: Update extension to use event system of phpunit/phpunit:10.0.0
1 parent a05623c commit 00e07ed

11 files changed

+221
-130
lines changed

.github/workflows/integrate.yaml

+5-31
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,10 @@ jobs:
1515
runs-on: "ubuntu-latest"
1616

1717
strategy:
18-
fail-fast: false
19-
2018
matrix:
21-
include:
22-
- php-version: "7.2"
23-
phpunit-version: "8.*"
24-
25-
- php-version: "7.3"
26-
phpunit-version: "8.*"
27-
28-
- php-version: "7.3"
29-
phpunit-version: "9.*"
30-
31-
- php-version: "7.4"
32-
phpunit-version: "8.*"
33-
34-
- php-version: "7.4"
35-
phpunit-version: "9.*"
36-
37-
- php-version: "8.0"
38-
phpunit-version: "8.*"
39-
40-
- php-version: "8.0"
41-
phpunit-version: "9.*"
42-
43-
- php-version: "8.1"
44-
phpunit-version: "8.*"
45-
46-
- php-version: "8.1"
47-
phpunit-version: "9.*"
19+
php-version:
20+
- "8.1"
21+
- "8.2"
4822

4923
steps:
5024
- name: "Checkout"
@@ -69,8 +43,8 @@ jobs:
6943
key: "php-${{ matrix.php-version }}-composer-${{ matrix.phpunit-version }}"
7044
restore-keys: "php-${{ matrix.php-version }}-composer-"
7145

72-
- name: "Require phpunit/phpunit ${{ matrix.phpunit-version }}"
73-
run: "composer require phpunit/phpunit:${{ matrix.phpunit-version }}"
46+
- name: "Install dependencies with composer"
47+
run: "composer install --no-interaction --no-progress"
7448

7549
- name: "Run tests with phpunit/phpunit"
7650
run: "vendor/bin/phpunit"

README.md

+8-16
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Enable with all defaults by adding the following code to your project's `phpunit
2525
<phpunit bootstrap="vendor/autoload.php">
2626
...
2727
<extensions>
28-
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
28+
<bootstrap class="JohnKary\PHPUnit\Extension\SpeedTrapExtension" />
2929
</extensions>
3030
</phpunit>
3131
```
@@ -46,18 +46,10 @@ Each parameter is set in `phpunit.xml`:
4646
<!-- ... other suite configuration here ... -->
4747

4848
<extensions>
49-
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap">
50-
<arguments>
51-
<array>
52-
<element key="slowThreshold">
53-
<integer>500</integer>
54-
</element>
55-
<element key="reportLength">
56-
<integer>10</integer>
57-
</element>
58-
</array>
59-
</arguments>
60-
</extension>
49+
<bootstrap class="JohnKary\PHPUnit\Extension\SpeedTrapExtension">
50+
<parameter name="slowThreshold" value="500" />
51+
<parameter name="reportLength" value="10" />
52+
</bootstrap>
6153
</extensions>
6254
</phpunit>
6355
```
@@ -132,7 +124,7 @@ Step 1) Enable SpeedTrap in phpunit.xml. The slowness report will output during
132124
<phpunit bootstrap="vendor/autoload.php">
133125
...
134126
<extensions>
135-
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
127+
<bootstrap class="JohnKary\PHPUnit\Extension\SpeedTrapExtension" />
136128
</extensions>
137129
</phpunit>
138130
```
@@ -165,7 +157,7 @@ Step 1) Setup phpunit.xml to enable SpeedTrap, but disable slowness profiling by
165157
</php>
166158
167159
<extensions>
168-
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
160+
<bootstrap class="JohnKary\PHPUnit\Extension\SpeedTrapExtension" />
169161
</extensions>
170162
</phpunit>
171163
```
@@ -192,7 +184,7 @@ The easiest way to set environment variables for the script `simple-phpunit` is
192184
</php>
193185
194186
<extensions>
195-
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
187+
<bootstrap class="JohnKary\PHPUnit\Extension\SpeedTrapExtension" />
196188
</extensions>
197189
</phpunit>
198190
```

composer.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
}
2020
],
2121
"require": {
22-
"php": ">=7.2",
23-
"phpunit/phpunit": "^8.0 || ^9.0"
22+
"php": "^8.1",
23+
"phpunit/phpunit": "^10.0.0"
2424
},
25+
"minimum-stability": "dev",
26+
"prefer-stable": true,
2527
"extra": {
2628
"branch-alias": {
2729
"dev-master": "5.0-dev"

phpunit.xml.dist

+7-14
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
<!-- https://phpunit.readthedocs.io/en/stable/configuration.html -->
33
<phpunit
44
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation = "https://schema.phpunit.de/9.3/phpunit.xsd"
5+
xsi:noNamespaceSchemaLocation = "https://schema.phpunit.de/10.0/phpunit.xsd"
66
colors = "true"
7-
bootstrap = "vendor/autoload.php">
7+
bootstrap = "vendor/autoload.php"
8+
>
89

910
<coverage>
1011
<include>
@@ -19,18 +20,10 @@
1920
</testsuites>
2021

2122
<extensions>
22-
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap">
23-
<arguments>
24-
<array>
25-
<element key="slowThreshold">
26-
<integer>500</integer>
27-
</element>
28-
<element key="reportLength">
29-
<integer>5</integer>
30-
</element>
31-
</array>
32-
</arguments>
33-
</extension>
23+
<bootstrap class="JohnKary\PHPUnit\Extension\SpeedTrapExtension">
24+
<parameter name="slowThreshold" value="500"/>
25+
<parameter name="reportLength" value="5"/>
26+
</bootstrap>
3427
</extensions>
3528

3629
</phpunit>

src/PreparedTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace JohnKary\PHPUnit\Extension;
6+
7+
use PHPUnit\Event;
8+
9+
final class PreparedTest
10+
{
11+
public function __construct(
12+
private readonly Event\Code\Test $test,
13+
private readonly Event\Telemetry\HRTime $start
14+
) {
15+
}
16+
17+
public function test(): Event\Code\Test
18+
{
19+
return $this->test;
20+
}
21+
22+
public function start(): Event\Telemetry\HRTime
23+
{
24+
return $this->start;
25+
}
26+
}

src/RecordThatTestHasBeenPrepared.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace JohnKary\PHPUnit\Extension;
6+
7+
use PHPUnit\Event;
8+
9+
final class RecordThatTestHasBeenPrepared implements Event\Test\PreparedSubscriber
10+
{
11+
public function __construct(private readonly SpeedTrap $speedTrap)
12+
{
13+
}
14+
15+
public function notify(Event\Test\Prepared $event): void
16+
{
17+
$this->speedTrap->recordThatTestHasBeenPrepared(
18+
$event->test(),
19+
$event->telemetryInfo()->time(),
20+
);
21+
}
22+
}

src/RecordThatTestHasPassed.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace JohnKary\PHPUnit\Extension;
6+
7+
use PHPUnit\Event;
8+
9+
final class RecordThatTestHasPassed implements Event\Test\PassedSubscriber
10+
{
11+
public function __construct(private readonly SpeedTrap $speedTrap)
12+
{
13+
}
14+
15+
public function notify(Event\Test\Passed $event): void
16+
{
17+
$this->speedTrap->recordThatTestHasPassed(
18+
$event->test(),
19+
$event->telemetryInfo()->time(),
20+
);
21+
}
22+
}

src/ShowSlowTests.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace JohnKary\PHPUnit\Extension;
6+
7+
use PHPUnit\Event;
8+
9+
final class ShowSlowTests implements Event\TestRunner\ExecutionFinishedSubscriber
10+
{
11+
public function __construct(private readonly SpeedTrap $speedTrap)
12+
{
13+
}
14+
15+
public function notify(Event\TestRunner\ExecutionFinished $event): void
16+
{
17+
$this->speedTrap->showSlowTests();
18+
}
19+
}

0 commit comments

Comments
 (0)