Skip to content

Commit

Permalink
Enhancement: Add support for phpunit/phpunit:^9.6.13
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Nov 5, 2023
1 parent 9774914 commit a55e345
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 39 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ 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
composer require phpunit/phpunit:10.4.2 --no-interaction --no-progress
vendor/bin/phpunit --configuration=test/Unit/phpunit.xml
vendor/bin/phpunit --configuration=test/EndToEnd/phpunit.xml
composer require phpunit/phpunit:10.4.2 --no-interaction --no-progress
vendor/bin/phpunit --configuration=test/EndToEnd/Version10/phpunit.xml
git checkout HEAD -- composer.json composer.lock

vendor: composer.json composer.lock
composer validate --strict
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": "~8.1.0 || ~8.2.0 || ~8.3.0",
"phpunit/phpunit": "^10.4.2"
"phpunit/phpunit": "^9.6.13 || ^10.4.2"
},
"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.

13 changes: 13 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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 Down
91 changes: 55 additions & 36 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,69 @@
use PHPUnit\Runner;
use PHPUnit\TextUI;

final class Extension implements Runner\Extension\Extension
{
public function bootstrap(
TextUI\Configuration\Configuration $configuration,
Runner\Extension\Facade $facade,
Runner\Extension\ParameterCollection $parameters,
): void {
if ($configuration->noOutput()) {
return;
}
if (1 !== \preg_match('/(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/', Runner\Version::id(), $matches)) {
throw new \RuntimeException(\sprintf(
'Unable to determine PHPUnit version from version identifier "%s".',
Runner\Version::id(),
));

Check warning on line 23 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L19-L23

Added lines #L19 - L23 were not covered by tests
}

$maximumCount = Count::fromInt(10);
$major = (int) $matches['major'];

Check warning on line 26 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L26

Added line #L26 was not covered by tests

if ($parameters->has('maximum-count')) {
$maximumCount = Count::fromInt((int) $parameters->get('maximum-count'));
}
if (10 <= $major) {

Check warning on line 28 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L28

Added line #L28 was not covered by tests
/**
* @internal
*/
final class Extension implements Runner\Extension\Extension
{
public function bootstrap(

Check warning on line 34 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L34

Added line #L34 was not covered by tests
TextUI\Configuration\Configuration $configuration,
Runner\Extension\Facade $facade,
Runner\Extension\ParameterCollection $parameters,
): void {
if ($configuration->noOutput()) {
return;

Check warning on line 40 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L39-L40

Added lines #L39 - L40 were not covered by tests
}

$maximumDuration = Duration::fromMilliseconds(500);
$maximumCount = Count::fromInt(10);

Check warning on line 43 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L43

Added line #L43 was not covered by tests

if ($parameters->has('maximum-duration')) {
$maximumDuration = Duration::fromMilliseconds((int) $parameters->get('maximum-duration'));
}
if ($parameters->has('maximum-count')) {
$maximumCount = Count::fromInt((int) $parameters->get('maximum-count'));

Check warning on line 46 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L45-L46

Added lines #L45 - L46 were not covered by tests
}

$collector = new Collector\DefaultCollector();
$maximumDuration = Duration::fromMilliseconds(500);

Check warning on line 49 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L49

Added line #L49 was not covered by tests

$reporter = new Reporter\DefaultReporter(
new Formatter\DefaultDurationFormatter(),
$maximumDuration,
$maximumCount,
);
if ($parameters->has('maximum-duration')) {
$maximumDuration = Duration::fromMilliseconds((int) $parameters->get('maximum-duration'));

Check warning on line 52 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L51-L52

Added lines #L51 - L52 were not covered by tests
}

$timeKeeper = new TimeKeeper();
$collector = new Collector\DefaultCollector();

Check warning on line 55 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L55

Added line #L55 was not covered by tests

$facade->registerSubscribers(
new Subscriber\TestPreparedSubscriber($timeKeeper),
new Subscriber\TestPassedSubscriber(
$reporter = new Reporter\DefaultReporter(
new Formatter\DefaultDurationFormatter(),

Check warning on line 58 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L57-L58

Added lines #L57 - L58 were not covered by tests
$maximumDuration,
$timeKeeper,
$collector,
),
new Subscriber\TestRunnerExecutionFinishedSubscriber(
$collector,
$reporter,
),
);
$maximumCount,
);

Check warning on line 61 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L60-L61

Added lines #L60 - L61 were not covered by tests

$timeKeeper = new TimeKeeper();

Check warning on line 63 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L63

Added line #L63 was not covered by tests

$facade->registerSubscribers(
new Subscriber\TestPreparedSubscriber($timeKeeper),
new Subscriber\TestPassedSubscriber(
$maximumDuration,
$timeKeeper,
$collector,
),
new Subscriber\TestRunnerExecutionFinishedSubscriber(
$collector,
$reporter,
),
);

Check warning on line 76 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L65-L76

Added lines #L65 - L76 were not covered by tests
}
}
} else {
throw new \RuntimeException(\sprintf(
'Unable to select extension for PHPUnit version with version identifier "%s".',
Runner\Version::id(),
));

Check warning on line 83 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L80-L83

Added lines #L80 - L83 were not covered by tests
}

0 comments on commit a55e345

Please sign in to comment.