Skip to content

Commit e01dfaa

Browse files
kubawerlossebastianbergmann
authored andcommitted
Fix test with data provider and dependency which does not return value
1 parent 2a39812 commit e01dfaa

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Framework/TestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,10 @@ private function handleDependencies(): bool
18001800
return true;
18011801
}
18021802

1803+
if (!$passedTests->hasReturnValue($dependencyTarget)) {
1804+
return true;
1805+
}
1806+
18031807
$returnValue = $passedTests->returnValue($dependencyTarget);
18041808

18051809
if ($dependency->deepClone()) {

src/Runner/TestResult/PassedTests.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111

1212
use function array_merge;
1313
use function assert;
14+
use function explode;
1415
use function in_array;
1516
use PHPUnit\Event\Code\TestMethod;
1617
use PHPUnit\Framework\TestSize\Known;
1718
use PHPUnit\Framework\TestSize\TestSize;
1819
use PHPUnit\Metadata\Api\Groups;
20+
use ReflectionMethod;
21+
use ReflectionNamedType;
1922

2023
/**
2124
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
@@ -113,6 +116,13 @@ public function isGreaterThan(string $method, TestSize $other): bool
113116
return $size->isGreaterThan($other);
114117
}
115118

119+
public function hasReturnValue(string $method): mixed
120+
{
121+
$returnType = (new ReflectionMethod(...explode('::', $method)))->getReturnType();
122+
123+
return !$returnType instanceof ReflectionNamedType || !in_array($returnType->getName(), ['never', 'void'], true);
124+
}
125+
116126
public function returnValue(string $method): mixed
117127
{
118128
if (isset($this->passedTestMethods[$method])) {

0 commit comments

Comments
 (0)