Skip to content
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

Enhancement: Add support for phpunit/phpunit:^12.0.0 #651

Merged
merged 1 commit into from
Feb 7, 2025
Merged
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
4 changes: 4 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ branches:
- context: "Tests (11.0.0, 8.3, lowest)"
- context: "Tests (11.3.6, 8.4, highest)"
- context: "Tests (11.3.6, 8.4, lowest)"
- context: "Tests (12.0.0, 8.3, highest)"
- context: "Tests (12.0.0, 8.3, lowest)"
- context: "Tests (12.0.0, 8.4, highest)"
- context: "Tests (12.0.0, 8.4, lowest)"
strict: false
restrictions:

Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,22 @@ jobs:
php-version: "8.4"
dependencies: "highest"

- phpunit-version: "12.0.0"
php-version: "8.3"
dependencies: "lowest"

- phpunit-version: "12.0.0"
php-version: "8.3"
dependencies: "highest"

- phpunit-version: "12.0.0"
php-version: "8.4"
dependencies: "lowest"

- phpunit-version: "12.0.0"
php-version: "8.4"
dependencies: "highest"

env:
PHPUNIT_SLOW_TEST_DETECTOR_PHAR: ".build/phar/phpunit-slow-test-detector.phar"

Expand Down Expand Up @@ -772,6 +788,10 @@ jobs:
if: "matrix.phpunit-version == '11.0.0'"
run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version11/phpunit.xml"

- name: "Run end-to-end tests with phpunit/phpunit:12.0.0"
if: "matrix.phpunit-version == '12.0.0'"
run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version12/phpunit.xml"

- name: "Download Phar"
uses: "actions/[email protected]"
with:
Expand Down Expand Up @@ -809,3 +829,7 @@ jobs:
- name: "Run phar tests with phpunit/phpunit:11.0.0"
if: "matrix.phpunit-version == '11.0.0'"
run: "vendor/bin/phpunit --colors=always --configuration=test/Phar/Version11/phpunit.xml"

- name: "Run phar tests with phpunit/phpunit:12.0.0"
if: "matrix.phpunit-version == '12.0.0'"
run: "vendor/bin/phpunit --colors=always --configuration=test/Phar/Version12/phpunit.xml"
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

For a full diff see [`2.17.0...main`][2.17.0...main].

### Added

- Added support for `phpunit/phpunit:^12.0.0` ([#651]), by [@localheinz]

## [`2.17.0`][2.17.0]

For a full diff see [`2.16.1...2.17.0`][2.16.1...2.17.0].
Expand Down Expand Up @@ -380,6 +384,7 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0].
[#598]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/598
[#604]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/604
[#635]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/635
[#651]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/651

[@dantleech]: https://github.com/dantleech
[@HypeMC]: https://github.com/HypeMC
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The extension is compatible with the following versions of `phpunit/phpunit`:
- [`phpunit/phpunit:^9.0.0`](https://github.com/sebastianbergmann/phpunit/tree/9.0.0)
- [`phpunit/phpunit:^10.0.0`](https://github.com/sebastianbergmann/phpunit/tree/10.0.0)
- [`phpunit/phpunit:^11.0.0`](https://github.com/sebastianbergmann/phpunit/tree/11.0.0)
- [`phpunit/phpunit:^12.0.0`](https://github.com/sebastianbergmann/phpunit/tree/12.0.0)

## Installation

Expand Down Expand Up @@ -104,11 +105,13 @@ To bootstrap the extension as a `composer` package when using

- `phpunit/phpunit:^10.0.0`
- `phpunit/phpunit:^11.0.0`
- `phpunit/phpunit:^12.0.0`

adjust your `phpunit.xml` configuration file and configure the

- [`extensions` element](https://docs.phpunit.de/en/10.5/configuration.html#the-extensions-element) on [`phpunit/phpunit:^10.0.0`](https://docs.phpunit.de/en/10.5/)
- [`extensions` element](https://docs.phpunit.de/en/11.0/configuration.html#the-extensions-element) on [`phpunit/phpunit:^11.0.0`](https://docs.phpunit.de/en/11.0/)
- [`extensions` element](https://docs.phpunit.de/en/12.0/configuration.html#the-extensions-element) on [`phpunit/phpunit:^12.0.0`](https://docs.phpunit.de/en/12.0/)

```diff
<phpunit
Expand Down Expand Up @@ -163,11 +166,13 @@ To bootstrap the extension as a PHAR when using

- `phpunit/phpunit:^10.0.0`
- `phpunit/phpunit:^11.0.0`
- `phpunit/phpunit:^12.0.0`

adjust your `phpunit.xml` configuration file and configure the

- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/10.5/configuration.html#the-extensionsdirectory-attribute) and the [`extensions` element](https://docs.phpunit.de/en/10.5/configuration.html#the-extensions-element) on [`phpunit/phpunit:^10.0.0`](https://docs.phpunit.de/en/10.5/)
- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/11.0/configuration.html#the-extensionsdirectory-attribute) and the [`extensions` element](https://docs.phpunit.de/en/11.0/configuration.html#the-extensions-element) on [`phpunit/phpunit:^11.0.0`](https://docs.phpunit.de/en/11.0/)
- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/12.0/configuration.html#the-extensionsdirectory-attribute) and the [`extensions` element](https://docs.phpunit.de/en/12.0/configuration.html#the-extensions-element) on [`phpunit/phpunit:^12.0.0`](https://docs.phpunit.de/en/12.0/)

```diff
<phpunit
Expand Down Expand Up @@ -284,11 +289,13 @@ To configure the extension when using

- `phpunit/phpunit:^10.0.0`
- `phpunit/phpunit:^11.0.0`
- `phpunit/phpunit:^12.0.0`

adjust your `phpunit.xml` configuration file and configure one or more

- [`parameter` elements](https://docs.phpunit.de/en/10.5/configuration.html#the-parameter-element) on [`phpunit/phpunit:^10.0.0`](https://docs.phpunit.de/en/10.5/)
- [`parameter` elements](https://docs.phpunit.de/en/11.0/configuration.html#the-parameter-element) on [`phpunit/phpunit:^11.0.0`](https://docs.phpunit.de/en/11.0/)
- [`parameter` elements](https://docs.phpunit.de/en/12.0/configuration.html#the-parameter-element) on [`phpunit/phpunit:^12.0.0`](https://docs.phpunit.de/en/12.0/)

The following example configures the maximum count of slow tests to three, and the maximum duration for all tests to 250 milliseconds:

Expand Down Expand Up @@ -320,6 +327,7 @@ You can configure the maximum duration for a single test case with
- an `Attribute\MaximumDuration` attribute when using
- `phpunit/phpunit:^10.0.0`
- `phpunit/phpunit:^11.0.0`
- `phpunit/phpunit:^12.0.0`
- a `@maximumDuration` annotation in the DocBlock when using
- `phpunit/phpunit:^6.5.0`
- `phpunit/phpunit:^7.5.0`
Expand Down Expand Up @@ -450,6 +458,7 @@ When using

- `phpunit/phpunit:^10.0.0`
- `phpunit/phpunit:^11.0.0`
- `phpunit/phpunit:^12.0.0`

the extension uses the new event system of `phpunit/phpunit`.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require": {
"php": "~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
"phpunit/phpunit": "^6.5.0 || ^7.5.0 || ^8.5.19 || ^9.0.0 || ^10.0.0 || ^11.0.0"
"phpunit/phpunit": "^6.5.0 || ^7.5.0 || ^8.5.19 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.45.0",
Expand Down
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="ergebnis/phpunit-slow-test-detector" version="2.17.0" type="extension">
<extension for="phpunit/phpunit" compatible="^7.5 || 8.5 || ^9.0 || ^10.0 || ^11.0"/>
<extension for="phpunit/phpunit" compatible="^7.5 || 8.5 || ^9.0 || ^10.0 || ^11.0 || ^12.0"/>
</contains>

<copyright>
Expand Down
15 changes: 15 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,21 @@ parameters:
count: 1
path: test/Unit/Version/MajorTest.php

-
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\Version\\\\MajorTest\\:\\:testIsLessThanReturnsFalseWhenValueIsGreater\\(\\) has no return type specified\\.$#"
count: 1
path: test/Unit/Version/MajorTest.php

-
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\Version\\\\MajorTest\\:\\:testIsLessThanReturnsFalseWhenValueIsSame\\(\\) has no return type specified\\.$#"
count: 1
path: test/Unit/Version/MajorTest.php

-
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\Version\\\\MajorTest\\:\\:testIsLessThanReturnsTrueWhenValueIsLess\\(\\) has no return type specified\\.$#"
count: 1
path: test/Unit/Version/MajorTest.php

-
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\Version\\\\MajorTest\\:\\:testIsOneOfReturnsFalseWhenAllValuesAreDifferent\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
6 changes: 4 additions & 2 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPUnit\SlowTestDetector;

use Ergebnis\PHPUnit;
use PHPUnit\Framework;
use PHPUnit\Runner;
use PHPUnit\TextUI;
Expand Down Expand Up @@ -406,7 +407,7 @@
return;
}

if ($phpUnitVersionSeries->major()->isOneOf(Version\Major::fromInt(10), Version\Major::fromInt(11))) {
if ($phpUnitVersionSeries->major()->isOneOf(Version\Major::fromInt(10), Version\Major::fromInt(11), Version\Major::fromInt(12))) {

Check warning on line 410 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L410

Added line #L410 was not covered by tests
/**
* @internal
*/
Expand Down Expand Up @@ -446,7 +447,8 @@
new Subscriber\Test\FinishedSubscriber(
$maximumDuration,
$timeKeeper,
$collector
$collector,
Version\Series::fromString(Runner\Version::series())

Check warning on line 451 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L450-L451

Added lines #L450 - L451 were not covered by tests
),
new Subscriber\TestRunner\ExecutionFinishedSubscriber(
$collector,
Expand Down
18 changes: 14 additions & 4 deletions src/Subscriber/Test/FinishedSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Ergebnis\PHPUnit\SlowTestDetector\TestIdentifier;
use Ergebnis\PHPUnit\SlowTestDetector\Time;
use Ergebnis\PHPUnit\SlowTestDetector\TimeKeeper;
use Ergebnis\PHPUnit\SlowTestDetector\Version;
use PHPUnit\Event;
use PHPUnit\Framework;
use PHPUnit\Metadata;
Expand All @@ -46,14 +47,21 @@ final class FinishedSubscriber implements Event\Test\FinishedSubscriber
*/
private $collector;

/**
* @var Version\Series
*/
private $versionSeries;

public function __construct(
Duration $maximumDuration,
TimeKeeper $timeKeeper,
Collector\Collector $collector
Collector\Collector $collector,
Version\Series $versionSeries
) {
$this->maximumDuration = $maximumDuration;
$this->timeKeeper = $timeKeeper;
$this->collector = $collector;
$this->versionSeries = $versionSeries;
}

/**
Expand Down Expand Up @@ -152,10 +160,12 @@ private function resolveMaximumDuration(Event\Code\Test $test): Duration
return $maximumDurationFromAttribute;
}

$maximumDurationFromAnnotation = self::resolveMaximumDurationFromAnnotation($test);
if ($this->versionSeries->major()->isLessThan(Version\Major::fromInt(12))) {
$maximumDurationFromAnnotation = self::resolveMaximumDurationFromAnnotation($test);

if ($maximumDurationFromAnnotation instanceof Duration) {
return $maximumDurationFromAnnotation;
if ($maximumDurationFromAnnotation instanceof Duration) {
return $maximumDurationFromAnnotation;
}
}

return $this->maximumDuration;
Expand Down
5 changes: 5 additions & 0 deletions src/Version/Major.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public function equals(self $other): bool
return $this->value === $other->value;
}

public function isLessThan(self $other): bool
{
return $this->value < $other->value;
}

public function isOneOf(self ...$others): bool
{
foreach ($others as $other) {
Expand Down
60 changes: 60 additions & 0 deletions test/EndToEnd/Version12/Configuration/Defaults/SleeperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021-2025 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/phpunit-slow-test-detector
*/

namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\Defaults;

use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)]
final class SleeperTest extends Framework\TestCase
{
public function testSleeperSleepsLessThanDefaultMaximumDuration(): void
{
$milliseconds = 10;

$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);

$sleeper->sleep();

self::assertSame($milliseconds, $sleeper->milliseconds());
}

#[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanDefaultMaximumDuration')]
public function testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider(int $milliseconds): void
{
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);

$sleeper->sleep();

self::assertSame($milliseconds, $sleeper->milliseconds());
}

/**
* @return \Generator<int, array{0: int}>
*/
public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): iterable
{
$values = \range(
600,
1600,
100
);

foreach ($values as $value) {
yield $value => [
$value,
];
}
}
}
32 changes: 32 additions & 0 deletions test/EndToEnd/Version12/Configuration/Defaults/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.0/phpunit.xsd"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
bootstrap="../../../../../vendor/autoload.php"
cacheResult="false"
colors="true"
columns="max"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
executionOrder="default"
requireCoverageMetadata="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
>
<extensions>
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
</extensions>
<testsuites>
<testsuite name="Unit Tests">
<directory>.</directory>
</testsuite>
</testsuites>
</phpunit>
Loading
Loading