Skip to content

Commit

Permalink
feat: adds "phpunit/phpunit": "^10.3.1" support
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Aug 4, 2023
1 parent cbcea04 commit 3742e74
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 88 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
],
"require": {
"php": "^8.1.0",
"brianium/paratest": "^7.2.3",
"nunomaduro/collision": "^7.7.0",
"brianium/paratest": "^7.2.4",
"nunomaduro/collision": "^7.8.0",
"nunomaduro/termwind": "^1.15.1",
"pestphp/pest-plugin": "^2.0.1",
"pestphp/pest-plugin-arch": "^2.2.3",
"phpunit/phpunit": "^10.2.7"
"phpunit/phpunit": "^10.3.1"
},
"conflict": {
"webmozart/assert": "<1.11.0",
"phpunit/phpunit": ">10.2.7"
"phpunit/phpunit": ">10.3.1"
},
"autoload": {
"psr-4": {
Expand Down
33 changes: 17 additions & 16 deletions src/Plugins/Parallel/Paratest/WrapperRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use function dirname;
use function file_get_contents;
use function max;
use NunoMaduro\Collision\Adapters\Phpunit\Support\ResultReflection;
use ParaTest\Coverage\CoverageMerger;
use ParaTest\JUnit\LogMerger;
use ParaTest\JUnit\Writer;
Expand Down Expand Up @@ -273,7 +274,7 @@ private function complete(TestResult $testResultSum): int
assert($testResult instanceof TestResult);

$testResultSum = new TestResult(
$testResultSum->numberOfTests() + $testResult->numberOfTests(),
(int) $testResultSum->hasTests() + (int) $testResult->hasTests(),
$testResultSum->numberOfTestsRun() + $testResult->numberOfTestsRun(),
$testResultSum->numberOfAssertions() + $testResult->numberOfAssertions(),
array_merge_recursive($testResultSum->testErroredEvents(), $testResult->testErroredEvents()),
Expand All @@ -282,23 +283,23 @@ private function complete(TestResult $testResultSum): int
array_merge_recursive($testResultSum->testSuiteSkippedEvents(), $testResult->testSuiteSkippedEvents()),
array_merge_recursive($testResultSum->testSkippedEvents(), $testResult->testSkippedEvents()),
array_merge_recursive($testResultSum->testMarkedIncompleteEvents(), $testResult->testMarkedIncompleteEvents()),
array_merge_recursive($testResultSum->testTriggeredDeprecationEvents(), $testResult->testTriggeredDeprecationEvents()),
array_merge_recursive($testResultSum->testTriggeredPhpDeprecationEvents(), $testResult->testTriggeredPhpDeprecationEvents()),
array_merge_recursive($testResultSum->testTriggeredPhpunitDeprecationEvents(), $testResult->testTriggeredPhpunitDeprecationEvents()),
array_merge_recursive($testResultSum->testTriggeredErrorEvents(), $testResult->testTriggeredErrorEvents()),
array_merge_recursive($testResultSum->testTriggeredNoticeEvents(), $testResult->testTriggeredNoticeEvents()),
array_merge_recursive($testResultSum->testTriggeredPhpNoticeEvents(), $testResult->testTriggeredPhpNoticeEvents()),
array_merge_recursive($testResultSum->testTriggeredWarningEvents(), $testResult->testTriggeredWarningEvents()),
array_merge_recursive($testResultSum->testTriggeredPhpWarningEvents(), $testResult->testTriggeredPhpWarningEvents()),
array_merge_recursive($testResultSum->testTriggeredPhpunitErrorEvents(), $testResult->testTriggeredPhpunitErrorEvents()),
array_merge_recursive($testResultSum->testTriggeredPhpunitWarningEvents(), $testResult->testTriggeredPhpunitWarningEvents()),
array_merge_recursive($testResultSum->testRunnerTriggeredDeprecationEvents(), $testResult->testRunnerTriggeredDeprecationEvents()),
array_merge_recursive($testResultSum->testRunnerTriggeredWarningEvents(), $testResult->testRunnerTriggeredWarningEvents()),
array_merge_recursive($testResultSum->errors(), $testResult->errors()),
array_merge_recursive($testResultSum->deprecations(), $testResult->deprecations()),
array_merge_recursive($testResultSum->notices(), $testResult->notices()),
array_merge_recursive($testResultSum->warnings(), $testResult->warnings()),
array_merge_recursive($testResultSum->phpDeprecations(), $testResult->phpDeprecations()),
array_merge_recursive($testResultSum->phpNotices(), $testResult->phpNotices()),
array_merge_recursive($testResultSum->phpWarnings(), $testResult->phpWarnings()),
);
}

$testResultSum = new TestResult(
$testResultSum->numberOfTests(),
ResultReflection::numberOfTests($testResultSum),
$testResultSum->numberOfTestsRun(),
$testResultSum->numberOfAssertions(),
$testResultSum->testErroredEvents(),
Expand All @@ -307,21 +308,21 @@ private function complete(TestResult $testResultSum): int
$testResultSum->testSuiteSkippedEvents(),
$testResultSum->testSkippedEvents(),
$testResultSum->testMarkedIncompleteEvents(),
$testResultSum->testTriggeredDeprecationEvents(),
$testResultSum->testTriggeredPhpDeprecationEvents(),
$testResultSum->testTriggeredPhpunitDeprecationEvents(),
$testResultSum->testTriggeredErrorEvents(),
$testResultSum->testTriggeredNoticeEvents(),
$testResultSum->testTriggeredPhpNoticeEvents(),
$testResultSum->testTriggeredWarningEvents(),
$testResultSum->testTriggeredPhpWarningEvents(),
$testResultSum->testTriggeredPhpunitErrorEvents(),
$testResultSum->testTriggeredPhpunitWarningEvents(),
$testResultSum->testRunnerTriggeredDeprecationEvents(),
array_values(array_filter(
$testResultSum->testRunnerTriggeredWarningEvents(),
fn (WarningTriggered $event): bool => ! str_contains($event->message(), 'No tests found')
)),
$testResultSum->errors(),
$testResultSum->deprecations(),
$testResultSum->notices(),
$testResultSum->warnings(),
$testResultSum->phpDeprecations(),
$testResultSum->phpNotices(),
$testResultSum->phpWarnings(),
);

$this->printer->printResults(
Expand Down
4 changes: 4 additions & 0 deletions src/Plugins/Parallel/Support/CompactPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public function recap(State $state, PHPUnitTestResult $testResult, Duration $dur
null,
null,
null,
null,
null,
null,
null,
);

$telemetry = new Info(
Expand Down
9 changes: 5 additions & 4 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Pest;

use NunoMaduro\Collision\Adapters\Phpunit\Support\ResultReflection;
use PHPUnit\TestRunner\TestResult\TestResult;
use PHPUnit\TextUI\Configuration\Configuration;

Expand Down Expand Up @@ -44,7 +45,7 @@ public static function exitCode(Configuration $configuration, TestResult $result
return self::SUCCESS_EXIT;
}

if ($configuration->failOnEmptyTestSuite() && $result->numberOfTests() === 0) {
if ($configuration->failOnEmptyTestSuite() && ResultReflection::numberOfTests($result) === 0) {
return self::FAILURE_EXIT;
}

Expand All @@ -53,9 +54,9 @@ public static function exitCode(Configuration $configuration, TestResult $result
$returnCode = self::FAILURE_EXIT;
}

$warnings = $result->numberOfTestsWithTestTriggeredPhpunitWarningEvents()
+ $result->numberOfTestsWithTestTriggeredWarningEvents()
+ $result->numberOfTestsWithTestTriggeredPhpWarningEvents();
$warnings = $result->numberOfTestsWithTestTriggeredPhpunitWarningEvents() +
+count($result->warnings())
+ count($result->phpWarnings());

if ($configuration->failOnWarning() && $warnings > 0) {
$returnCode = self::FAILURE_EXIT;
Expand Down
98 changes: 55 additions & 43 deletions src/Support/StateGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,64 +74,76 @@ public function fromPhpUnitTestResult(int $passedTests, PHPUnitTestResult $testR
));
}

foreach ($testResult->testTriggeredDeprecationEvents() as $testResultEvent) {
$testResultEvent = $testResultEvent[0];
foreach ($testResult->deprecations() as $testResultEvent) {
foreach ($testResultEvent->triggeringTests() as $triggeringTest) {
['test' => $test] = $triggeringTest;

$state->add(TestResult::fromPestParallelTestCase(
$testResultEvent->test(),
TestResult::DEPRECATED,
ThrowableBuilder::from(new TestOutcome($testResultEvent->message()))
));
$state->add(TestResult::fromPestParallelTestCase(
$test,
TestResult::DEPRECATED,
ThrowableBuilder::from(new TestOutcome($testResultEvent->description()))
));
}
}

foreach ($testResult->testTriggeredPhpDeprecationEvents() as $testResultEvent) {
$testResultEvent = $testResultEvent[0];
foreach ($testResult->phpDeprecations() as $testResultEvent) {
foreach ($testResultEvent->triggeringTests() as $triggeringTest) {
['test' => $test] = $triggeringTest;

$state->add(TestResult::fromPestParallelTestCase(
$testResultEvent->test(),
TestResult::DEPRECATED,
ThrowableBuilder::from(new TestOutcome($testResultEvent->message()))
));
$state->add(TestResult::fromPestParallelTestCase(
$test,
TestResult::DEPRECATED,
ThrowableBuilder::from(new TestOutcome($testResultEvent->description()))
));
}
}

foreach ($testResult->testTriggeredNoticeEvents() as $testResultEvent) {
$testResultEvent = $testResultEvent[0];
foreach ($testResult->notices() as $testResultEvent) {
foreach ($testResultEvent->triggeringTests() as $triggeringTest) {
['test' => $test] = $triggeringTest;

$state->add(TestResult::fromPestParallelTestCase(
$testResultEvent->test(),
TestResult::NOTICE,
ThrowableBuilder::from(new TestOutcome($testResultEvent->message()))
));
$state->add(TestResult::fromPestParallelTestCase(
$test,
TestResult::NOTICE,
ThrowableBuilder::from(new TestOutcome($testResultEvent->description()))
));
}
}

foreach ($testResult->testTriggeredPhpNoticeEvents() as $testResultEvent) {
$testResultEvent = $testResultEvent[0];
foreach ($testResult->phpNotices() as $testResultEvent) {
foreach ($testResultEvent->triggeringTests() as $triggeringTest) {
['test' => $test] = $triggeringTest;

$state->add(TestResult::fromPestParallelTestCase(
$testResultEvent->test(),
TestResult::NOTICE,
ThrowableBuilder::from(new TestOutcome($testResultEvent->message()))
));
$state->add(TestResult::fromPestParallelTestCase(
$test,
TestResult::NOTICE,
ThrowableBuilder::from(new TestOutcome($testResultEvent->description()))
));
}
}

foreach ($testResult->testTriggeredWarningEvents() as $testResultEvent) {
$testResultEvent = $testResultEvent[0];
foreach ($testResult->warnings() as $testResultEvent) {
foreach ($testResultEvent->triggeringTests() as $triggeringTest) {
['test' => $test] = $triggeringTest;

$state->add(TestResult::fromPestParallelTestCase(
$testResultEvent->test(),
TestResult::WARN,
ThrowableBuilder::from(new TestOutcome($testResultEvent->message()))
));
$state->add(TestResult::fromPestParallelTestCase(
$test,
TestResult::WARN,
ThrowableBuilder::from(new TestOutcome($testResultEvent->description()))
));
}
}

foreach ($testResult->testTriggeredPhpWarningEvents() as $testResultEvent) {
$testResultEvent = $testResultEvent[0];
foreach ($testResult->phpWarnings() as $testResultEvent) {
foreach ($testResultEvent->triggeringTests() as $triggeringTest) {
['test' => $test] = $triggeringTest;

$state->add(TestResult::fromPestParallelTestCase(
$testResultEvent->test(),
TestResult::WARN,
ThrowableBuilder::from(new TestOutcome($testResultEvent->message()))
));
$state->add(TestResult::fromPestParallelTestCase(
$test,
TestResult::WARN,
ThrowableBuilder::from(new TestOutcome($testResultEvent->description()))
));
}
}

// for each test that passed, we need to add it to the state
Expand All @@ -140,7 +152,7 @@ public function fromPhpUnitTestResult(int $passedTests, PHPUnitTestResult $testR
new TestMethod(
"$i", // @phpstan-ignore-line
'', // @phpstan-ignore-line
'',
'', // @phpstan-ignore-line
1,
TestDoxBuilder::fromClassNameAndMethodName('', ''), // @phpstan-ignore-line
MetadataCollection::fromArray([]),
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion tests/.snapshots/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1210,4 +1210,4 @@
WARN Tests\Visual\Version
- visual snapshot of help command output

Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 860 passed (1979 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 860 passed (1975 assertions)

0 comments on commit 3742e74

Please sign in to comment.