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:^7.2.0 #447

Merged
merged 1 commit into from
Dec 21, 2023
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: 3 additions & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ branches:
required_approving_review_count: 1
required_status_checks:
checks:
- context: "Code Coverage (8.5.19, 7.4, highest)"
- context: "Code Coverage (7.2.0, 7.4, highest)"
- context: "Coding Standards (7.4, locked)"
- context: "Compile Phar (8.1, locked)"
- context: "Dependency Analysis (7.4, locked)"
- context: "Refactoring (7.4, locked)"
- context: "Security Analysis (7.4, locked)"
- context: "Static Code Analysis (7.4, locked)"
- context: "Tests (7.2.0, 7.4, highest)"
- context: "Tests (7.2.0, 7.4, lowest)"
- context: "Tests (8.5.19, 7.4, highest)"
- context: "Tests (8.5.19, 7.4, lowest)"
- context: "Tests (8.5.19, 8.0, highest)"
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
phpunit-version:
- "8.5.19"
- "7.2.0"

php-version:
- "7.4"
Expand Down Expand Up @@ -473,6 +473,14 @@ jobs:
- "highest"

include:
- phpunit-version: "7.2.0"
php-version: "7.4"
dependencies: "lowest"

- phpunit-version: "7.2.0"
php-version: "7.4"
dependencies: "highest"

- phpunit-version: "10.0.0"
php-version: "8.1"
dependencies: "lowest"
Expand Down Expand Up @@ -556,8 +564,8 @@ jobs:
with:
dependencies: "${{ matrix.dependencies }}"

- name: "Run unit tests with phpunit/phpunit:8.5.19"
if: "matrix.phpunit-version == '8.5.19'"
- name: "Run unit tests with phpunit/phpunit:7.2.0"
if: "matrix.phpunit-version == '7.2.0'"
run: "vendor/bin/phpunit --colors=always --configuration=test/Unit/phpunit.xml"

- name: "Apply patch from https://github.com/sebastianbergmann/phpunit/pull/4486 for phpunit/phpunit:9.0.0"
Expand All @@ -567,6 +575,10 @@ jobs:
wget -O gh-4486.patch https://github.com/sebastianbergmann/phpunit/commit/0a488f22925b3c8732338ef0fbfe7f13cb4cf1d2.patch
patch -p1 < gh-4486.patch

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

- name: "Run end-to-end tests with phpunit/phpunit:8.5.19"
if: "matrix.phpunit-version == '8.5.19'"
run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version08/phpunit.xml"
Expand Down
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.7.0...main`][2.7.0...main].

### Added

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

## [`2.7.0`][2.7.0]

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

[@HypeMC]: https://github.com/HypeMC
[@localheinz]: https://github.com/localheinz
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ static-code-analysis-baseline: vendor ## Generates a baseline for static code an
.PHONY: tests
tests: ## Runs unit and end-to-end tests with phpunit/phpunit
mkdir -p .build/phpunit/
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
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
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
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
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
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
Expand Down
64 changes: 59 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This project provides a [`composer`](https://getcomposer.org) package and a [Pha

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

- [`phpunit/phpunit:^7.2.0`](https://github.com/sebastianbergmann/phpunit/tree/7.2.0)

Choose a reason for hiding this comment

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

Suggested change
- [`phpunit/phpunit:^7.2.0`](https://github.com/sebastianbergmann/phpunit/tree/7.2.0)
- [`phpunit/phpunit:^7.1.0`](https://github.com/sebastianbergmann/phpunit/tree/7.1.0)

As of composer.json

- [`phpunit/phpunit:^8.5.19`](https://github.com/sebastianbergmann/phpunit/tree/8.5.19)
- [`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)
Expand All @@ -30,7 +31,7 @@ Run
composer require --dev ergebnis/phpunit-slow-test-detector
```

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`.
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`.

### Installation as Phar

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

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.

### Bootstrapping the extension as a `composer` package when using `phpunit/phpunit:^7.2.0`

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):

```diff
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
>
+ <extensions>
+ <extension class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
+ </extensions>
<testsuites>
<testsuite name="unit">
<directory>test/Unit/</directory>
</testsuite>
</testsuites>
</phpunit>
```

### Bootstrapping the extension as a `composer` package when using `phpunit/phpunit:^8.5.19`

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):
Expand Down Expand Up @@ -136,6 +158,38 @@ You can configure the extension with the following options in your `phpunit.xml`

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

### Configuring the extension when using `phpunit/phpunit:^7.2.0`

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`:

```diff
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
>
<extensions>
- <extension class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
+ <extension class="Ergebnis\PHPUnit\SlowTestDetector\Extension">
+ <arguments>
+ <array>
+ <element key="maximum-count">
+ <integer>3</integer>
+ </element>
+ <element key="maximum-duration">
+ <integer>250</integer>
+ </element>
+ </array>
+ </arguments>
+ </extension>
</extensions>
<testsuites>
<testsuite name="unit">
<directory>test/Unit/</directory>
</testsuite>
</testsuites>
</phpunit>
```
### Configuring the extension when using `phpunit/phpunit:^8.5.19`

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`:
Expand Down Expand Up @@ -232,8 +286,8 @@ The following example configures the maximum count of slow tests to three, and t
You can configure the maximum duration for a single test case with

- an `Attribute\MaximumDuration` attribute when using `phpunit/phpunit:^10.0.0`
- a `@maximumDuration` annotation in the DocBlock when using `phpunit/phpunit:^8.5.19` or `phpunit/phpunit:^9.0.0`
- a `@slowThreshold` annotation in the DocBlock when using `phpunit/phpunit:^8.5.19` or `phpunit/phpunit:^9.0.0`
- a `@maximumDuration` annotation in the DocBlock when using `phpunit/phpunit:^7.2.0`, `phpunit/phpunit:^8.5.19`, or `phpunit/phpunit:^9.0.0`
- a `@slowThreshold` annotation in the DocBlock when using `phpunit/phpunit:^7.2.0`, `phpunit/phpunit:^8.5.19`, or `phpunit/phpunit:^9.0.0`

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

Expand Down Expand Up @@ -316,9 +370,9 @@ Time: 00:12.601, Memory: 8.00 MB
OK (13 tests, 13 assertions)
```

### Understanding measured test durations when using `phpunit/phpunit:^8.5.19` or `phpunit/phpunit:^9.0.0`
### Understanding measured test durations when using `phpunit/phpunit:^7.2.0`, `phpunit/phpunit:^8.5.19`, or `phpunit/phpunit:^9.0.0`

When using `phpunit/phpunit:^8.5.19` or `phpunit/phpunit:^9.0.0`, the extension uses the hooks event system of `phpunit/phpunit`.
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`.

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

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.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0",
"phpunit/phpunit": "^8.5.19 || ^9.0.0 || ^10.0.0"
"phpunit/phpunit": "^7.1.0 || ^8.5.19 || ^9.0.0 || ^10.0.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.28.3",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

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

36 changes: 36 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,42 @@
<code>$reporter</code>
</UnusedParam>
</file>
<file src="test/EndToEnd/Version07/TestCase/Combination/SleeperTest.php">
<PossiblyUnusedMethod>
<code>sleepWithAfterAnnotation</code>
<code>sleepWithAfterClassAnnotation</code>
<code>sleepWithBeforeAnnotation</code>
<code>sleepWithBeforeClassAnnotation</code>
</PossiblyUnusedMethod>
</file>
<file src="test/EndToEnd/Version07/TestCase/WithAfterAnnotation/SleeperTest.php">
<PossiblyUnusedMethod>
<code>sleepWithAfterAnnotation</code>
</PossiblyUnusedMethod>
</file>
<file src="test/EndToEnd/Version07/TestCase/WithAfterClassAnnotation/SleeperTest.php">
<PossiblyUnusedMethod>
<code>sleepWithAfterClassAnnotation</code>
</PossiblyUnusedMethod>
</file>
<file src="test/EndToEnd/Version07/TestCase/WithBeforeAnnotation/SleeperTest.php">
<PossiblyUnusedMethod>
<code>sleepWithBeforeAnnotation</code>
</PossiblyUnusedMethod>
</file>
<file src="test/EndToEnd/Version07/TestCase/WithBeforeClassAnnotation/SleeperTest.php">
<PossiblyUnusedMethod>
<code>sleepWithBeforeClassAnnotation</code>
</PossiblyUnusedMethod>
</file>
<file src="test/EndToEnd/Version07/TestMethod/WithRunInSeparateProcessAnnotation/SleeperTest.php">
<PossiblyUnusedMethod>
<code>sleepWithAfterAnnotation</code>
<code>sleepWithAfterClassAnnotation</code>
<code>sleepWithBeforeAnnotation</code>
<code>sleepWithBeforeClassAnnotation</code>
</PossiblyUnusedMethod>
</file>
<file src="test/EndToEnd/Version08/TestCase/Combination/SleeperTest.php">
<PossiblyUnusedMethod>
<code>sleepWithAfterAnnotation</code>
Expand Down
2 changes: 1 addition & 1 deletion src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
));
}

if ($phpUnitVersionSeries->major()->isOneOf(Version\Major::fromInt(8), Version\Major::fromInt(9))) {
if ($phpUnitVersionSeries->major()->isOneOf(Version\Major::fromInt(7), Version\Major::fromInt(8), Version\Major::fromInt(9))) {

Check warning on line 29 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L29

Added line #L29 was not covered by tests
/**
* @internal
*/
Expand Down
64 changes: 64 additions & 0 deletions test/EndToEnd/Version07/Configuration/Defaults/SleeperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021-2023 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\Version07\Configuration\Defaults;

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

/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper
*/
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());
}

/**
* @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,
];
}
}
}
26 changes: 26 additions & 0 deletions test/EndToEnd/Version07/Configuration/Defaults/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.2/phpunit.xsd"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
bootstrap="../../../../../vendor/autoload.php"
colors="true"
columns="max"
forceCoversAnnotation="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="true"
>
<extensions>
<extension class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
</extensions>
<testsuites>
<testsuite name="Unit Tests">
<directory>.</directory>
</testsuite>
</testsuites>
</phpunit>
Loading