Skip to content

Commit

Permalink
Enhancement: Update extension to use event system of phpunit/phpunit:…
Browse files Browse the repository at this point in the history
…10.0.0
  • Loading branch information
localheinz committed Oct 24, 2022
1 parent a05623c commit dc9f3e2
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 128 deletions.
35 changes: 4 additions & 31 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,9 @@ jobs:
runs-on: "ubuntu-latest"

strategy:
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"

steps:
- name: "Checkout"
Expand All @@ -69,8 +42,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
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
}
],
"require": {
"php": ">=7.2",
"phpunit/phpunit": "^8.0 || ^9.0"
"php": "^8.1",
"phpunit/phpunit": "dev-main#5a201ebad as 10.0.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "5.0-dev"
Expand Down
18 changes: 5 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- 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">

Expand All @@ -19,18 +19,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

0 comments on commit dc9f3e2

Please sign in to comment.