Skip to content

Commit

Permalink
Merge pull request #423 from ergebnis/feature/phpunit-11
Browse files Browse the repository at this point in the history
Enhancement: Run end-to-end tests with `phpunit/phpunit:11.0.x-dev`
  • Loading branch information
localheinz committed Dec 17, 2023
2 parents 6fe2215 + e34021a commit f0a2b3b
Show file tree
Hide file tree
Showing 15 changed files with 724 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/settings.yml
Expand Up @@ -40,13 +40,15 @@ branches:
- context: "Tests (8.1, 9.0.0, lowest)"
- context: "Tests (8.2, 10.0.0, highest)"
- context: "Tests (8.2, 10.0.0, lowest)"
- context: "Tests (8.2, 11.0.x-dev, highest)"
- context: "Tests (8.2, 8.5.19, highest)"
- context: "Tests (8.2, 8.5.19, locked)"
- context: "Tests (8.2, 8.5.19, lowest)"
- context: "Tests (8.2, 9.0.0, highest)"
- context: "Tests (8.2, 9.0.0, lowest)"
- context: "Tests (8.3, 10.0.0, highest)"
- context: "Tests (8.3, 10.0.0, lowest)"
- context: "Tests (8.3, 11.0.x-dev, highest)"
- context: "Tests (8.3, 8.5.19, highest)"
- context: "Tests (8.3, 8.5.19, locked)"
- context: "Tests (8.3, 8.5.19, lowest)"
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/integrate.yaml
Expand Up @@ -521,6 +521,10 @@ jobs:
phpunit-version: "10.0.0"
dependencies: "highest"

- php-version: "8.2"
phpunit-version: "11.0.x-dev"
dependencies: "highest"

- php-version: "8.3"
phpunit-version: "9.0.0"
dependencies: "lowest"
Expand All @@ -537,6 +541,10 @@ jobs:
phpunit-version: "10.0.0"
dependencies: "highest"

- php-version: "8.3"
phpunit-version: "11.0.x-dev"
dependencies: "highest"

steps:
- name: "Checkout"
uses: "actions/checkout@v4.1.1"
Expand Down Expand Up @@ -576,9 +584,13 @@ jobs:
run: "composer remove ergebnis/php-cs-fixer-config psalm/plugin-phpunit vimeo/psalm --ansi --dev --no-interaction --no-progress"

- name: "Require phpunit/phpunit:^${{ matrix.phpunit-version }}"
if: "matrix.dependencies != 'locked'"
if: "matrix.dependencies != 'locked' && matrix.phpunit-version != '11.0.x-dev'"
run: "composer require phpunit/phpunit:^${{ matrix.phpunit-version }} --ansi --no-interaction --no-progress --update-with-all-dependencies"

- name: "Require phpunit/phpunit:${{ matrix.phpunit-version }}"
if: "matrix.dependencies != 'locked' && matrix.phpunit-version == '11.0.x-dev'"
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/install@1.8.0"
with:
Expand Down Expand Up @@ -606,3 +618,7 @@ jobs:
- name: "Run end-to-end tests with phpunit/phpunit:10.0.0"
if: "matrix.phpunit-version == '10.0.0'"
run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version10/phpunit.xml"

- name: "Run end-to-end tests with phpunit/phpunit:11.0.x-dev"
if: "matrix.phpunit-version == '11.0.x-dev'"
run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version10/phpunit.xml"
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -64,6 +64,7 @@ tests: ## Runs unit and end-to-end tests with phpunit/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/EndToEnd/Version8/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/Version9/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
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:11.0.x-dev --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/EndToEnd/Version11/phpunit.xml; git checkout HEAD -- composer.json composer.lock

vendor: composer.json composer.lock
composer validate --strict
Expand Down
10 changes: 10 additions & 0 deletions psalm-baseline.xml
Expand Up @@ -70,6 +70,16 @@
<code>provideMillisecondsGreaterThanDefaultMaximumDuration</code>
</PossiblyUnusedMethod>
</file>
<file src="test/EndToEnd/Version11/CustomConfiguration/SleeperTest.php">
<PossiblyUnusedMethod>
<code>provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration</code>
</PossiblyUnusedMethod>
</file>
<file src="test/EndToEnd/Version11/DefaultConfiguration/SleeperTest.php">
<PossiblyUnusedMethod>
<code>provideMillisecondsGreaterThanDefaultMaximumDuration</code>
</PossiblyUnusedMethod>
</file>
<file src="test/Fixture/Sleeper.php">
<ArgumentTypeCoercion>
<code><![CDATA[$this->milliseconds * 1000]]></code>
Expand Down
2 changes: 1 addition & 1 deletion src/Extension.php
Expand Up @@ -170,7 +170,7 @@ private function resolveMaximumDuration(string $test): Duration
return;
}

if ($phpUnitVersionSeries->major()->equals(Version\Major::fromInt(10))) {
if ($phpUnitVersionSeries->major()->isOneOf(Version\Major::fromInt(10), Version\Major::fromInt(11))) {
/**
* @internal
*/
Expand Down
49 changes: 49 additions & 0 deletions test/EndToEnd/Version11/CustomConfiguration/SleeperTest.php
@@ -0,0 +1,49 @@
<?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\Version11\CustomConfiguration;

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

#[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)]
final class SleeperTest extends Framework\TestCase
{
#[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')]
public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(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 provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable
{
$values = \range(
300,
500,
50,
);

foreach ($values as $value) {
yield $value => [
$value,
];
}
}
}
29 changes: 29 additions & 0 deletions test/EndToEnd/Version11/CustomConfiguration/phpunit.xml
@@ -0,0 +1,29 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
bootstrap="../../../../vendor/autoload.php"
cacheResult="false"
colors="true"
columns="max"
executionOrder="random"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
>
<extensions>
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension">
<parameter name="maximum-count" value="3"/>
<parameter name="maximum-duration" value="300"/>
</bootstrap>
</extensions>
<testsuites>
<testsuite name="Unit Tests">
<directory>.</directory>
</testsuite>
</testsuites>
</phpunit>
36 changes: 36 additions & 0 deletions test/EndToEnd/Version11/CustomConfiguration/test.phpt
@@ -0,0 +1,36 @@
--TEST--
Configuring "maximum-count" parameter to 3 and "maximum-duration" parameter to 300 milliseconds
--FILE--
<?php

declare(strict_types=1);

use PHPUnit\TextUI;

$_SERVER['argv'][] = '--configuration=test/EndToEnd/Version11/CustomConfiguration/phpunit.xml';

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

$application = new TextUI\Application();

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

Runtime: %s
Configuration: %Stest/EndToEnd/Version11/CustomConfiguration/phpunit.xml
Random %seed: %s

..... 5 / 5 (100%)

Detected 5 tests that took longer than expected.

1. 0.5%s (0.300) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version11\CustomConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider#4
2. 0.4%s (0.300) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version11\CustomConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider#3
3. 0.4%s (0.300) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version11\CustomConfiguration\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider#2

There are 2 additional slow tests that are not listed here.

Time: %s, Memory: %s

OK (5 tests, 5 assertions)

0 comments on commit f0a2b3b

Please sign in to comment.