Skip to content

Enhancement: Add support for phpunit/phpunit:^9.6.0 #341

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

Merged
merged 1 commit into from
Nov 7, 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
27 changes: 18 additions & 9 deletions .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@ branches:
- context: "Refactoring (8.1, locked)"
- context: "Security Analysis (8.1, locked)"
- context: "Static Code Analysis (8.1, locked)"
- context: "Tests (8.1, highest)"
- context: "Tests (8.1, locked)"
- context: "Tests (8.1, lowest)"
- context: "Tests (8.2, highest)"
- context: "Tests (8.2, locked)"
- context: "Tests (8.2, lowest)"
- context: "Tests (8.3, highest)"
- context: "Tests (8.3, locked)"
- context: "Tests (8.3, lowest)"
- context: "Tests (8.1, 10.4.0, highest)"
- context: "Tests (8.1, 10.4.0, locked)"
- context: "Tests (8.1, 10.4.0, lowest)"
- context: "Tests (8.1, 9.6.0, highest)"
- context: "Tests (8.1, 9.6.0, locked)"
- context: "Tests (8.1, 9.6.0, lowest)"
- context: "Tests (8.2, 10.4.0, highest)"
- context: "Tests (8.2, 10.4.0, locked)"
- context: "Tests (8.2, 10.4.0, lowest)"
- context: "Tests (8.2, 9.6.0, highest)"
- context: "Tests (8.2, 9.6.0, locked)"
- context: "Tests (8.2, 9.6.0, lowest)"
- context: "Tests (8.3, 10.4.0, highest)"
- context: "Tests (8.3, 10.4.0, locked)"
- context: "Tests (8.3, 10.4.0, lowest)"
- context: "Tests (8.3, 9.6.0, highest)"
- context: "Tests (8.3, 9.6.0, locked)"
- context: "Tests (8.3, 9.6.0, lowest)"
strict: false
restrictions:

Expand Down
23 changes: 18 additions & 5 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ jobs:
- "8.2"
- "8.3"

phpunit-version:
- "9.6.0"
- "10.4.0"

dependencies:
- "lowest"
- "locked"
Expand Down Expand Up @@ -481,16 +485,25 @@ jobs:
uses: "actions/[email protected]"
with:
path: "${{ env.COMPOSER_CACHE_DIR }}"
key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-"
key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-phpunit-${{ matrix.phpunit-version }}-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-phpunit-${{ matrix.phpunit-version }}-"

- name: "Require phpunit/phpunit:^${{ matrix.phpunit-version }}"
run: "composer require phpunit/phpunit:^${{ matrix.phpunit-version }} --ansi --no-interaction --no-progress --update-with-all-dependencies"

- name: "Install ${{ matrix.dependencies }} dependencies with composer"
uses: "ergebnis/.github/actions/composer/[email protected]"
with:
dependencies: "${{ matrix.dependencies }}"

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

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

- name: "Run end-to-end tests with phpunit/phpunit:9.6.0"
if: "matrix.phpunit-version == '9.6.0'"
run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version9/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.3.2...main`][2.3.2...main].

### Added

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

### Changed

- Extracted `Duration` ([#351]), by [@localheinz]
Expand Down Expand Up @@ -175,6 +179,7 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0].
[#272]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/272
[#273]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/273
[#340]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/340
[#341]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/341
[#342]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/342
[#343]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/343
[#350]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/350
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ static-code-analysis-baseline: vendor ## Generates a baseline for static code an
.PHONY: tests
tests: vendor ## Runs unit and end-to-end tests with phpunit/phpunit
mkdir -p .build/phpunit
vendor/bin/phpunit --configuration=test/Unit/phpunit.xml
vendor/bin/phpunit --configuration=test/EndToEnd/phpunit.xml
composer require phpunit/phpunit:10.4.0 --no-interaction --no-progress --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/Unit/phpunit.xml; git checkout HEAD -- composer.json composer.lock; composer install --no-interaction --no-progress
composer require phpunit/phpunit:10.4.0 --no-interaction --no-progress --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/EndToEnd/Version10/phpunit.xml; git checkout HEAD -- composer.json composer.lock; composer install --no-interaction --no-progress
composer require phpunit/phpunit:9.6.0 --no-interaction --no-progress --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/EndToEnd/Version9/phpunit.xml; git checkout HEAD -- composer.json composer.lock; composer install --no-interaction --no-progress

vendor: composer.json composer.lock
composer validate --strict
Expand Down
56 changes: 53 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Download `phpunit-slow-test-detector.phar` from the [latest release](https://git

### Bootstrapping the extension as a `composer` package

To bootstrap the extension as a `composer` package, adjust your `phpunit.xml` configuration file and configure the [`<extensions>` element](https://docs.phpunit.de/en/10.4/configuration.html#the-extensions-element):
To bootstrap the extension as a `composer` package when using `phpunit/phpunit:^10.4.0`, adjust your `phpunit.xml` configuration file and configure the [`extensions` element](https://docs.phpunit.de/en/10.4/configuration.html#the-extensions-element):

```diff
<phpunit
Expand All @@ -53,9 +53,28 @@ To bootstrap the extension as a `composer` package, adjust your `phpunit.xml` co
</phpunit>
```

To bootstrap the extension as a `composer` package when using `phpunit/phpunit:^9.6.0`, adjust your `phpunit.xml` configuration file and configure the [`extensions` element](https://docs.phpunit.de/en/9.6/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 PHAR

To bootstrap the extension as a PHAR, adjust your `phpunit.xml` configuration file and configure the [`extensionsDirectory` attribute](https://docs.phpunit.de/en/10.4/configuration.html#the-extensionsdirectory-attribute) of the [`<phpunit>` element](https://docs.phpunit.de/en/10.4/configuration.html#the-phpunit-element):
To bootstrap the extension as a PHAR when using `phpunit/phpunit:^10.4.0`, adjust your `phpunit.xml` configuration file and configure the [`extensionsDirectory` attribute](https://docs.phpunit.de/en/10.4/configuration.html#the-extensionsdirectory-attribute) of the [`<phpunit>` element](https://docs.phpunit.de/en/10.4/configuration.html#the-phpunit-element):

```diff
<phpunit
Expand All @@ -82,7 +101,7 @@ You can configure the extension with the following parameters in your `phpunit.x
- `maximum-count`, an `int`, the maximum count of slow test that should be listed, defaults to `10`
- `maximum-duration`, an `int`, the maximum duration in milliseconds for all tests, defaults to `500`

The following example configures the maximum count of slow tests to three, and the maximum duration for all tests to 250 milliseconds:
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:^10.4.0`:

```diff
<phpunit
Expand All @@ -105,6 +124,37 @@ The following example configures the maximum count of slow tests to three, and t
</phpunit>
```

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:^9.6.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 maximum duration per test case

You can configure the maximum duration for a single test with a `@maximumDuration` (or `@slowThreshold`) annotation in the DocBlock.
Expand Down
6 changes: 5 additions & 1 deletion composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"symbol-whitelist": []
"symbol-whitelist": [
"PHPUnit\\Runner\\AfterLastTestHook",
"PHPUnit\\Runner\\AfterSuccessfulTestHook",
"PHPUnit\\Runner\\BeforeFirstTestHook"
]
}
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": "~8.1.0 || ~8.2.0 || ~8.3.0",
"phpunit/phpunit": "^10.4.0"
"phpunit/phpunit": "^9.6.0 || ^10.4.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.39.0",
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.

20 changes: 18 additions & 2 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<file src="src/Extension.php">
<DuplicateClass>
<code>Extension</code>
</DuplicateClass>
<UnusedClass>
<code>Extension</code>
</UnusedClass>
Expand Down Expand Up @@ -30,6 +33,19 @@
<MixedAssignment>
<code>$maximumDuration</code>
</MixedAssignment>
<UnusedClass>
<code>TestPassedSubscriber</code>
</UnusedClass>
</file>
<file src="src/Subscriber/TestPreparedSubscriber.php">
<UnusedClass>
<code>TestPreparedSubscriber</code>
</UnusedClass>
</file>
<file src="src/Subscriber/TestRunnerExecutionFinishedSubscriber.php">
<UnusedClass>
<code>TestRunnerExecutionFinishedSubscriber</code>
</UnusedClass>
</file>
<file src="test/Double/Collector/AppendingCollector.php">
<UnusedClass>
Expand All @@ -46,12 +62,12 @@
<code>NullReporter</code>
</UnusedClass>
</file>
<file src="test/EndToEnd/Default/SleeperTest.php">
<file src="test/EndToEnd/Version10/Default/SleeperTest.php">
<PossiblyUnusedMethod>
<code>provideMillisecondsGreaterThanDefaultMaximumDuration</code>
</PossiblyUnusedMethod>
</file>
<file src="test/EndToEnd/MaximumCount/Three/SleeperTest.php">
<file src="test/EndToEnd/Version10/MaximumCount/Three/SleeperTest.php">
<PossiblyUnusedMethod>
<code>provideMillisecondsGreaterThanDefaultMaximumDuration</code>
</PossiblyUnusedMethod>
Expand Down
4 changes: 0 additions & 4 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,4 @@
$rectorConfig->rules([
Php81\Rector\Property\ReadOnlyPropertyRector::class,
]);

$rectorConfig->sets([
PHPUnit\Set\PHPUnitSetList::PHPUNIT_100,
]);
};
Loading