Skip to content

Enhancement: Update extension to use event system of phpunit/phpunit:10.0.0 #98

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 5 additions & 29 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,9 @@ jobs:
fail-fast: false

matrix:
include:
- php-version: "7.2"
phpunit-version: "8.*"

- php-version: "7.3"
phpunit-version: "8.*"

- php-version: "7.3"
phpunit-version: "9.*"

- php-version: "7.4"
phpunit-version: "8.*"

- php-version: "7.4"
phpunit-version: "9.*"

- php-version: "8.0"
phpunit-version: "8.*"

- php-version: "8.0"
phpunit-version: "9.*"

- php-version: "8.1"
phpunit-version: "8.*"

- php-version: "8.1"
phpunit-version: "9.*"
php-version:
- "8.1"
- "8.2"

steps:
- name: "Checkout"
Expand All @@ -69,8 +45,8 @@ jobs:
key: "php-${{ matrix.php-version }}-composer-${{ matrix.phpunit-version }}"
restore-keys: "php-${{ matrix.php-version }}-composer-"

- name: "Require phpunit/phpunit ${{ matrix.phpunit-version }}"
run: "composer require phpunit/phpunit:${{ matrix.phpunit-version }}"
- name: "Install dependencies with composer"
run: "composer install --no-interaction --no-progress"

- name: "Run tests with phpunit/phpunit"
run: "vendor/bin/phpunit"
24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Enable with all defaults by adding the following code to your project's `phpunit
<phpunit bootstrap="vendor/autoload.php">
...
<extensions>
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
<bootstrap class="JohnKary\PHPUnit\Extension\SpeedTrapExtension" />
</extensions>
</phpunit>
```
Expand All @@ -46,18 +46,10 @@ Each parameter is set in `phpunit.xml`:
<!-- ... other suite configuration here ... -->

<extensions>
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap">
<arguments>
<array>
<element key="slowThreshold">
<integer>500</integer>
</element>
<element key="reportLength">
<integer>10</integer>
</element>
</array>
</arguments>
</extension>
<bootstrap class="JohnKary\PHPUnit\Extension\SpeedTrapExtension">
<parameter name="slowThreshold" value="500" />
<parameter name="reportLength" value="10" />
</bootstrap>
</extensions>
</phpunit>
```
Expand Down Expand Up @@ -132,7 +124,7 @@ Step 1) Enable SpeedTrap in phpunit.xml. The slowness report will output during
<phpunit bootstrap="vendor/autoload.php">
...
<extensions>
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
<bootstrap class="JohnKary\PHPUnit\Extension\SpeedTrapExtension" />
</extensions>
</phpunit>
```
Expand Down Expand Up @@ -165,7 +157,7 @@ Step 1) Setup phpunit.xml to enable SpeedTrap, but disable slowness profiling by
</php>

<extensions>
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
<bootstrap class="JohnKary\PHPUnit\Extension\SpeedTrapExtension" />
</extensions>
</phpunit>
```
Expand All @@ -192,7 +184,7 @@ The easiest way to set environment variables for the script `simple-phpunit` is
</php>

<extensions>
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap" />
<bootstrap class="JohnKary\PHPUnit\Extension\SpeedTrapExtension" />
</extensions>
</phpunit>
```
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
}
],
"require": {
"php": ">=7.2",
"phpunit/phpunit": "^8.0 || ^9.0"
"php": "^8.1",
"phpunit/phpunit": "^10.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how feasible is to keep currently still supported phpunit 9.x together with 10.x?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@localheinz can it be done, please, so this dep can be used for projects that still need PHP <8.1 support

},
"extra": {
"branch-alias": {
Expand Down
21 changes: 7 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<!-- https://phpunit.readthedocs.io/en/stable/configuration.html -->
<phpunit
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation = "https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation = "https://schema.phpunit.de/10.0/phpunit.xsd"
colors = "true"
bootstrap = "vendor/autoload.php">
bootstrap = "vendor/autoload.php"
>

<coverage>
<include>
Expand All @@ -19,18 +20,10 @@
</testsuites>

<extensions>
<extension class="JohnKary\PHPUnit\Extension\SpeedTrap">
<arguments>
<array>
<element key="slowThreshold">
<integer>500</integer>
</element>
<element key="reportLength">
<integer>5</integer>
</element>
</array>
</arguments>
</extension>
<bootstrap class="JohnKary\PHPUnit\Extension\SpeedTrapExtension">
<parameter name="slowThreshold" value="500"/>
<parameter name="reportLength" value="5"/>
</bootstrap>
</extensions>

</phpunit>
26 changes: 26 additions & 0 deletions src/PreparedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace JohnKary\PHPUnit\Extension;

use PHPUnit\Event;

final class PreparedTest
{
public function __construct(
private readonly Event\Code\Test $test,
private readonly Event\Telemetry\HRTime $start
) {
}

public function test(): Event\Code\Test
{
return $this->test;
}

public function start(): Event\Telemetry\HRTime
{
return $this->start;
}
}
22 changes: 22 additions & 0 deletions src/RecordThatTestHasBeenPrepared.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace JohnKary\PHPUnit\Extension;

use PHPUnit\Event;

final class RecordThatTestHasBeenPrepared implements Event\Test\PreparedSubscriber
{
public function __construct(private readonly SpeedTrap $speedTrap)
{
}

public function notify(Event\Test\Prepared $event): void
{
$this->speedTrap->recordThatTestHasBeenPrepared(
$event->test(),
$event->telemetryInfo()->time(),
);
}
}
22 changes: 22 additions & 0 deletions src/RecordThatTestHasPassed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace JohnKary\PHPUnit\Extension;

use PHPUnit\Event;

final class RecordThatTestHasPassed implements Event\Test\PassedSubscriber
{
public function __construct(private readonly SpeedTrap $speedTrap)
{
}

public function notify(Event\Test\Passed $event): void
{
$this->speedTrap->recordThatTestHasPassed(
$event->test(),
$event->telemetryInfo()->time(),
);
}
}
19 changes: 19 additions & 0 deletions src/ShowSlowTests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace JohnKary\PHPUnit\Extension;

use PHPUnit\Event;

final class ShowSlowTests implements Event\TestRunner\ExecutionFinishedSubscriber
{
public function __construct(private readonly SpeedTrap $speedTrap)
{
}

public function notify(Event\TestRunner\ExecutionFinished $event): void
{
$this->speedTrap->showSlowTests();
}
}
Loading