Skip to content

Commit 0547146

Browse files
authored
Merge pull request #447 from ergebnis/feature/phpunit-7
Enhancement: Add support for `phpunit/phpunit:^7.2.0`
2 parents 405e6b9 + 1f8dc80 commit 0547146

File tree

74 files changed

+3082
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+3082
-17
lines changed

.github/settings.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ branches:
1414
required_approving_review_count: 1
1515
required_status_checks:
1616
checks:
17-
- context: "Code Coverage (8.5.19, 7.4, highest)"
17+
- context: "Code Coverage (7.2.0, 7.4, highest)"
1818
- context: "Coding Standards (7.4, locked)"
1919
- context: "Compile Phar (8.1, locked)"
2020
- context: "Dependency Analysis (7.4, locked)"
2121
- context: "Refactoring (7.4, locked)"
2222
- context: "Security Analysis (7.4, locked)"
2323
- context: "Static Code Analysis (7.4, locked)"
24+
- context: "Tests (7.2.0, 7.4, highest)"
25+
- context: "Tests (7.2.0, 7.4, lowest)"
2426
- context: "Tests (8.5.19, 7.4, highest)"
2527
- context: "Tests (8.5.19, 7.4, lowest)"
2628
- context: "Tests (8.5.19, 8.0, highest)"

.github/workflows/integrate.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
matrix:
2121
phpunit-version:
22-
- "8.5.19"
22+
- "7.2.0"
2323

2424
php-version:
2525
- "7.4"
@@ -473,6 +473,14 @@ jobs:
473473
- "highest"
474474

475475
include:
476+
- phpunit-version: "7.2.0"
477+
php-version: "7.4"
478+
dependencies: "lowest"
479+
480+
- phpunit-version: "7.2.0"
481+
php-version: "7.4"
482+
dependencies: "highest"
483+
476484
- phpunit-version: "10.0.0"
477485
php-version: "8.1"
478486
dependencies: "lowest"
@@ -556,8 +564,8 @@ jobs:
556564
with:
557565
dependencies: "${{ matrix.dependencies }}"
558566

559-
- name: "Run unit tests with phpunit/phpunit:8.5.19"
560-
if: "matrix.phpunit-version == '8.5.19'"
567+
- name: "Run unit tests with phpunit/phpunit:7.2.0"
568+
if: "matrix.phpunit-version == '7.2.0'"
561569
run: "vendor/bin/phpunit --colors=always --configuration=test/Unit/phpunit.xml"
562570

563571
- name: "Apply patch from https://github.com/sebastianbergmann/phpunit/pull/4486 for phpunit/phpunit:9.0.0"
@@ -567,6 +575,10 @@ jobs:
567575
wget -O gh-4486.patch https://github.com/sebastianbergmann/phpunit/commit/0a488f22925b3c8732338ef0fbfe7f13cb4cf1d2.patch
568576
patch -p1 < gh-4486.patch
569577
578+
- name: "Run end-to-end tests with phpunit/phpunit:7.2.0"
579+
if: "matrix.phpunit-version == '7.2.0'"
580+
run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version07/phpunit.xml"
581+
570582
- name: "Run end-to-end tests with phpunit/phpunit:8.5.19"
571583
if: "matrix.phpunit-version == '8.5.19'"
572584
run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version08/phpunit.xml"

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88

99
For a full diff see [`2.7.0...main`][2.7.0...main].
1010

11+
### Added
12+
13+
- Added support for `phpunit/phpunit:^7.2.0` ([#447]), by [@localheinz]
14+
1115
## [`2.7.0`][2.7.0]
1216

1317
For a full diff see [`2.6.0...2.7.0`][2.6.0...2.7.0].
@@ -237,6 +241,7 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0].
237241
[#393]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/393
238242
[#394]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/394
239243
[#396]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/396
244+
[#447]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/447
240245

241246
[@HypeMC]: https://github.com/HypeMC
242247
[@localheinz]: https://github.com/localheinz

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ static-code-analysis-baseline: vendor ## Generates a baseline for static code an
6060
.PHONY: tests
6161
tests: ## Runs unit and end-to-end tests with phpunit/phpunit
6262
mkdir -p .build/phpunit/
63-
composer config platform.php --unset; composer remove ergebnis/php-cs-fixer-config psalm/plugin-phpunit vimeo/psalm --dev --no-interaction --no-progress; composer require phpunit/phpunit:^8.5.19 --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/Unit/phpunit.xml; git checkout HEAD -- composer.json composer.lock
63+
composer config platform.php --unset; composer remove ergebnis/php-cs-fixer-config psalm/plugin-phpunit vimeo/psalm --dev --no-interaction --no-progress; composer require phpunit/phpunit:^7.2.0 --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/Unit/phpunit.xml; git checkout HEAD -- composer.json composer.lock
64+
composer config platform.php --unset; composer remove ergebnis/php-cs-fixer-config psalm/plugin-phpunit vimeo/psalm --dev --no-interaction --no-progress; composer require phpunit/phpunit:^7.2.0 --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/EndToEnd/Version07/phpunit.xml; git checkout HEAD -- composer.json composer.lock
6465
composer config platform.php --unset; composer remove ergebnis/php-cs-fixer-config psalm/plugin-phpunit vimeo/psalm --dev --no-interaction --no-progress; composer require phpunit/phpunit:^8.5.19 --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/EndToEnd/Version08/phpunit.xml; git checkout HEAD -- composer.json composer.lock
6566
composer config platform.php --unset; composer remove ergebnis/php-cs-fixer-config psalm/plugin-phpunit vimeo/psalm --dev --no-interaction --no-progress; composer require phpunit/phpunit:^9.0.0 --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/EndToEnd/Version09/phpunit.xml; git checkout HEAD -- composer.json composer.lock
6667
composer config platform.php --unset; composer remove ergebnis/php-cs-fixer-config psalm/plugin-phpunit vimeo/psalm --dev --no-interaction --no-progress; composer require phpunit/phpunit:^10.0.0 --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/EndToEnd/Version10/phpunit.xml; git checkout HEAD -- composer.json composer.lock

README.md

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This project provides a [`composer`](https://getcomposer.org) package and a [Pha
1616

1717
The extension is compatible with the following versions of `phpunit/phpunit`:
1818

19+
- [`phpunit/phpunit:^7.2.0`](https://github.com/sebastianbergmann/phpunit/tree/7.2.0)
1920
- [`phpunit/phpunit:^8.5.19`](https://github.com/sebastianbergmann/phpunit/tree/8.5.19)
2021
- [`phpunit/phpunit:^9.0.0`](https://github.com/sebastianbergmann/phpunit/tree/9.0.0)
2122
- [`phpunit/phpunit:^10.0.0`](https://github.com/sebastianbergmann/phpunit/tree/10.0.0)
@@ -30,7 +31,7 @@ Run
3031
composer require --dev ergebnis/phpunit-slow-test-detector
3132
```
3233

33-
to install `ergebnis/phpunit-slow-test-detector` as a `composer` package when using `phpunit/phpunit:^8.5.19`, `phpunit/phpunit:^9.0.0`, or `phpunit/phpunit:^10.0.0`.
34+
to install `ergebnis/phpunit-slow-test-detector` as a `composer` package when using `phpunit/phpunit:^7.2.0`, `phpunit/phpunit:^8.5.19`, `phpunit/phpunit:^9.0.0`, or `phpunit/phpunit:^10.0.0`.
3435

3536
### Installation as Phar
3637

@@ -42,6 +43,27 @@ Download `phpunit-slow-test-detector.phar` from the [latest release](https://git
4243

4344
Before the extension can detect slow tests in `phpunit/phpunit`, you need to bootstrap it. The bootstrapping mechanism depends on the version of `phpunit/phpunit` you are using.
4445

46+
### Bootstrapping the extension as a `composer` package when using `phpunit/phpunit:^7.2.0`
47+
48+
To bootstrap the extension as a `composer` package when using `phpunit/phpunit:^7.2.0`, adjust your `phpunit.xml` configuration file and configure the [`extensions` element](https://docs.phpunit.de/en/7.5/configuration.html#the-extensions-element):
49+
50+
```diff
51+
<phpunit
52+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
53+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
54+
bootstrap="vendor/autoload.php"
55+
>
56+
+ <extensions>
57+
+ <extension class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
58+
+ </extensions>
59+
<testsuites>
60+
<testsuite name="unit">
61+
<directory>test/Unit/</directory>
62+
</testsuite>
63+
</testsuites>
64+
</phpunit>
65+
```
66+
4567
### Bootstrapping the extension as a `composer` package when using `phpunit/phpunit:^8.5.19`
4668

4769
To bootstrap the extension as a `composer` package when using `phpunit/phpunit:^8.5.19`, adjust your `phpunit.xml` configuration file and configure the [`extensions` element](https://docs.phpunit.de/en/8.5/configuration.html#the-extensions-element):
@@ -136,6 +158,38 @@ You can configure the extension with the following options in your `phpunit.xml`
136158

137159
The configuration mechanism depends on the version of `phpunit/phpunit` you are using.
138160

161+
### Configuring the extension when using `phpunit/phpunit:^7.2.0`
162+
163+
The following example configures the maximum count of slow tests to three, and the maximum duration for all tests to 250 milliseconds when using `phpunit/phpunit:^7.2.0`:
164+
165+
```diff
166+
<phpunit
167+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
168+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
169+
bootstrap="vendor/autoload.php"
170+
>
171+
<extensions>
172+
- <extension class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
173+
+ <extension class="Ergebnis\PHPUnit\SlowTestDetector\Extension">
174+
+ <arguments>
175+
+ <array>
176+
+ <element key="maximum-count">
177+
+ <integer>3</integer>
178+
+ </element>
179+
+ <element key="maximum-duration">
180+
+ <integer>250</integer>
181+
+ </element>
182+
+ </array>
183+
+ </arguments>
184+
+ </extension>
185+
</extensions>
186+
<testsuites>
187+
<testsuite name="unit">
188+
<directory>test/Unit/</directory>
189+
</testsuite>
190+
</testsuites>
191+
</phpunit>
192+
```
139193
### Configuring the extension when using `phpunit/phpunit:^8.5.19`
140194

141195
The following example configures the maximum count of slow tests to three, and the maximum duration for all tests to 250 milliseconds when using `phpunit/phpunit:^8.5.19`:
@@ -232,8 +286,8 @@ The following example configures the maximum count of slow tests to three, and t
232286
You can configure the maximum duration for a single test case with
233287

234288
- an `Attribute\MaximumDuration` attribute when using `phpunit/phpunit:^10.0.0`
235-
- a `@maximumDuration` annotation in the DocBlock when using `phpunit/phpunit:^8.5.19` or `phpunit/phpunit:^9.0.0`
236-
- a `@slowThreshold` annotation in the DocBlock when using `phpunit/phpunit:^8.5.19` or `phpunit/phpunit:^9.0.0`
289+
- a `@maximumDuration` annotation in the DocBlock when using `phpunit/phpunit:^7.2.0`, `phpunit/phpunit:^8.5.19`, or `phpunit/phpunit:^9.0.0`
290+
- a `@slowThreshold` annotation in the DocBlock when using `phpunit/phpunit:^7.2.0`, `phpunit/phpunit:^8.5.19`, or `phpunit/phpunit:^9.0.0`
237291

238292
The following example configures the maximum durations for single test cases to 5.000 ms, 4.000 ms, and 3.000 ms:
239293

@@ -316,9 +370,9 @@ Time: 00:12.601, Memory: 8.00 MB
316370
OK (13 tests, 13 assertions)
317371
```
318372

319-
### Understanding measured test durations when using `phpunit/phpunit:^8.5.19` or `phpunit/phpunit:^9.0.0`
373+
### Understanding measured test durations when using `phpunit/phpunit:^7.2.0`, `phpunit/phpunit:^8.5.19`, or `phpunit/phpunit:^9.0.0`
320374

321-
When using `phpunit/phpunit:^8.5.19` or `phpunit/phpunit:^9.0.0`, the extension uses the hooks event system of `phpunit/phpunit`.
375+
When using `phpunit/phpunit:^7.2.0`, `phpunit/phpunit:^8.5.19`, or `phpunit/phpunit:^9.0.0` the extension uses the hooks event system of `phpunit/phpunit`.
322376

323377
The hooks event system supports eleven hook methods that `phpunit/phpunit` invokes during the execution of tests.
324378

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"require": {
2727
"php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0",
28-
"phpunit/phpunit": "^8.5.19 || ^9.0.0 || ^10.0.0"
28+
"phpunit/phpunit": "^7.1.0 || ^8.5.19 || ^9.0.0 || ^10.0.0"
2929
},
3030
"require-dev": {
3131
"ergebnis/composer-normalize": "^2.28.3",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

psalm-baseline.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,42 @@
6060
<code>$reporter</code>
6161
</UnusedParam>
6262
</file>
63+
<file src="test/EndToEnd/Version07/TestCase/Combination/SleeperTest.php">
64+
<PossiblyUnusedMethod>
65+
<code>sleepWithAfterAnnotation</code>
66+
<code>sleepWithAfterClassAnnotation</code>
67+
<code>sleepWithBeforeAnnotation</code>
68+
<code>sleepWithBeforeClassAnnotation</code>
69+
</PossiblyUnusedMethod>
70+
</file>
71+
<file src="test/EndToEnd/Version07/TestCase/WithAfterAnnotation/SleeperTest.php">
72+
<PossiblyUnusedMethod>
73+
<code>sleepWithAfterAnnotation</code>
74+
</PossiblyUnusedMethod>
75+
</file>
76+
<file src="test/EndToEnd/Version07/TestCase/WithAfterClassAnnotation/SleeperTest.php">
77+
<PossiblyUnusedMethod>
78+
<code>sleepWithAfterClassAnnotation</code>
79+
</PossiblyUnusedMethod>
80+
</file>
81+
<file src="test/EndToEnd/Version07/TestCase/WithBeforeAnnotation/SleeperTest.php">
82+
<PossiblyUnusedMethod>
83+
<code>sleepWithBeforeAnnotation</code>
84+
</PossiblyUnusedMethod>
85+
</file>
86+
<file src="test/EndToEnd/Version07/TestCase/WithBeforeClassAnnotation/SleeperTest.php">
87+
<PossiblyUnusedMethod>
88+
<code>sleepWithBeforeClassAnnotation</code>
89+
</PossiblyUnusedMethod>
90+
</file>
91+
<file src="test/EndToEnd/Version07/TestMethod/WithRunInSeparateProcessAnnotation/SleeperTest.php">
92+
<PossiblyUnusedMethod>
93+
<code>sleepWithAfterAnnotation</code>
94+
<code>sleepWithAfterClassAnnotation</code>
95+
<code>sleepWithBeforeAnnotation</code>
96+
<code>sleepWithBeforeClassAnnotation</code>
97+
</PossiblyUnusedMethod>
98+
</file>
6399
<file src="test/EndToEnd/Version08/TestCase/Combination/SleeperTest.php">
64100
<PossiblyUnusedMethod>
65101
<code>sleepWithAfterAnnotation</code>

src/Extension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
));
2727
}
2828

29-
if ($phpUnitVersionSeries->major()->isOneOf(Version\Major::fromInt(8), Version\Major::fromInt(9))) {
29+
if ($phpUnitVersionSeries->major()->isOneOf(Version\Major::fromInt(7), Version\Major::fromInt(8), Version\Major::fromInt(9))) {
3030
/**
3131
* @internal
3232
*/
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Copyright (c) 2021-2023 Andreas Möller
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE.md file that was distributed with this source code.
10+
*
11+
* @see https://github.com/ergebnis/phpunit-slow-test-detector
12+
*/
13+
14+
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version07\Configuration\Defaults;
15+
16+
use Ergebnis\PHPUnit\SlowTestDetector\Test;
17+
use PHPUnit\Framework;
18+
19+
/**
20+
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper
21+
*/
22+
final class SleeperTest extends Framework\TestCase
23+
{
24+
public function testSleeperSleepsLessThanDefaultMaximumDuration(): void
25+
{
26+
$milliseconds = 10;
27+
28+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
29+
30+
$sleeper->sleep();
31+
32+
self::assertSame($milliseconds, $sleeper->milliseconds());
33+
}
34+
35+
/**
36+
* @dataProvider provideMillisecondsGreaterThanDefaultMaximumDuration
37+
*/
38+
public function testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider(int $milliseconds): void
39+
{
40+
$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);
41+
42+
$sleeper->sleep();
43+
44+
self::assertSame($milliseconds, $sleeper->milliseconds());
45+
}
46+
47+
/**
48+
* @return \Generator<int, array{0: int}>
49+
*/
50+
public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): iterable
51+
{
52+
$values = \range(
53+
600,
54+
1600,
55+
100,
56+
);
57+
58+
foreach ($values as $value) {
59+
yield $value => [
60+
$value,
61+
];
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)