Skip to content

Commit

Permalink
Enhancement: Add support for phpunit/phpunit:^12.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Feb 7, 2025
1 parent 10c7fab commit 1b0c9ea
Show file tree
Hide file tree
Showing 79 changed files with 3,222 additions and 6 deletions.
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
26 changes: 25 additions & 1 deletion .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 @@ -768,6 +784,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 @@ -800,4 +820,8 @@ 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"
run: "vendor/bin/phpunit --colors=always --configuration=test/Phar/Version12/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 @@ -452,6 +460,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.

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>
42 changes: 42 additions & 0 deletions test/EndToEnd/Version12/Configuration/Defaults/test.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
With default configuration
--FILE--
<?php

declare(strict_types=1);

use PHPUnit\TextUI;

$_SERVER['argv'][] = '--configuration=test/EndToEnd/Version12/Configuration/Defaults/phpunit.xml';

require_once __DIR__ . '/../../../../../vendor/autoload.php';

$application = new TextUI\Application();

$application->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s

Check failure on line 18 in test/EndToEnd/Version12/Configuration/Defaults/test.phpt

View workflow job for this annotation

GitHub Actions / Tests (12.0.0, 8.3, lowest)

Failed asserting that string matches format description.

Check failure on line 18 in test/EndToEnd/Version12/Configuration/Defaults/test.phpt

View workflow job for this annotation

GitHub Actions / Tests (12.0.0, 8.3, highest)

Failed asserting that string matches format description.

Check failure on line 18 in test/EndToEnd/Version12/Configuration/Defaults/test.phpt

View workflow job for this annotation

GitHub Actions / Tests (12.0.0, 8.4, lowest)

Failed asserting that string matches format description.

Check failure on line 18 in test/EndToEnd/Version12/Configuration/Defaults/test.phpt

View workflow job for this annotation

GitHub Actions / Tests (12.0.0, 8.4, highest)

Failed asserting that string matches format description.

Runtime: %s
Configuration: %s/EndToEnd/Version12/Configuration/Defaults/phpunit.xml

............ 12 / 12 (100%)

Detected 11 tests where the duration exceeded the maximum duration.

1. 1.6%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\Defaults\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #10 (1600)
2. 1.5%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\Defaults\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #9 (1500)
3. 1.4%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\Defaults\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #8 (1400)
4. 1.3%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\Defaults\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #7 (1300)
5. 1.2%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\Defaults\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #6 (1200)
6. 1.1%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\Defaults\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #5 (1100)
7. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\Defaults\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #4 (1000)
8. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\Defaults\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #3 (900)
9. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\Defaults\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #2 (800)
10. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\Defaults\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider with data set #1 (700)

There is 1 additional slow test that is not listed here.

Time: %s, Memory: %s

OK (12 tests, 12 assertions)
60 changes: 60 additions & 0 deletions test/EndToEnd/Version12/Configuration/MaximumCount/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\MaximumCount;

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,
1000,
100
);

foreach ($values as $value) {
yield $value => [
$value,
];
}
}
}
Loading

0 comments on commit 1b0c9ea

Please sign in to comment.