Skip to content

Commit 0de6612

Browse files
Merge branch '11.5' into 12.1
2 parents 840a6a0 + bfd0fc2 commit 0de6612

File tree

4 files changed

+94
-55
lines changed

4 files changed

+94
-55
lines changed

ChangeLog-12.1.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 12.1 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [12.1.1] - 2025-MM-DD
6+
7+
### Fixed
8+
9+
* [#6104](https://github.com/sebastianbergmann/phpunit/issues/6104): Test with dependencies and data provider fails
10+
511
## [12.1.0] - 2025-04-04
612

713
### Added
@@ -19,4 +25,5 @@ All notable changes of the PHPUnit 12.1 release series are documented in this fi
1925

2026
* [#6140](https://github.com/sebastianbergmann/phpunit/issues/6140): The `testClassName()` method on the `AfterTestMethodCalled`, `AfterTestMethodErrored`, `AfterTestMethodFinished`, `BeforeTestMethodCalled`, `BeforeTestMethodErrored`, `BeforeTestMethodFinished`, `PostConditionCalled`, `PostConditionErrored`, `PostConditionFinished`, `PreConditionCalled`, `PreConditionErrored`, and `PreConditionFinished` event value objects (use `test()->className()` instead)
2127

28+
[12.1.1]: https://github.com/sebastianbergmann/phpunit/compare/12.1.0...12.1
2229
[12.1.0]: https://github.com/sebastianbergmann/phpunit/compare/12.0.10...12.1.0

src/Framework/TestCase.php

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,54 +1113,6 @@ final protected function registerFailureType(string $classOrInterface): void
11131113
$this->failureTypes[$classOrInterface] = true;
11141114
}
11151115

1116-
/**
1117-
* @throws AssertionFailedError
1118-
* @throws Exception
1119-
* @throws ExpectationFailedException
1120-
* @throws Throwable
1121-
*
1122-
* @internal This method is not covered by the backward compatibility promise for PHPUnit
1123-
*/
1124-
final protected function runTest(): mixed
1125-
{
1126-
$testArguments = array_merge($this->data, array_values($this->dependencyInput));
1127-
1128-
$capture = tmpfile();
1129-
$errorLogPrevious = ini_set('error_log', stream_get_meta_data($capture)['uri']);
1130-
1131-
try {
1132-
/** @phpstan-ignore method.dynamicName */
1133-
$testResult = $this->{$this->methodName}(...$testArguments);
1134-
1135-
$errorLogOutput = stream_get_contents($capture);
1136-
1137-
if ($this->expectErrorLog) {
1138-
$this->assertNotEmpty($errorLogOutput, 'Test did not call error_log().');
1139-
} else {
1140-
// strip date from logged error, see https://github.com/php/php-src/blob/c696087e323263e941774ebbf902ac249774ec9f/main/main.c#L905
1141-
print preg_replace('/\[.+\] /', '', $errorLogOutput);
1142-
}
1143-
} catch (Throwable $exception) {
1144-
if (!$this->shouldExceptionExpectationsBeVerified($exception)) {
1145-
throw $exception;
1146-
}
1147-
1148-
$this->verifyExceptionExpectations($exception);
1149-
1150-
return null;
1151-
} finally {
1152-
if ($capture !== false) {
1153-
fclose($capture);
1154-
}
1155-
1156-
ini_set('error_log', $errorLogPrevious);
1157-
}
1158-
1159-
$this->expectedExceptionWasNotRaised();
1160-
1161-
return $testResult;
1162-
}
1163-
11641116
/**
11651117
* Creates a mock object for the specified interface or class.
11661118
*
@@ -1290,6 +1242,62 @@ protected function onNotSuccessfulTest(Throwable $t): never
12901242
throw $t;
12911243
}
12921244

1245+
/**
1246+
* @throws AssertionFailedError
1247+
* @throws Exception
1248+
* @throws ExpectationFailedException
1249+
* @throws Throwable
1250+
*/
1251+
private function runTest(): mixed
1252+
{
1253+
$testArguments = array_merge($this->data, array_values($this->dependencyInput));
1254+
$positionalArguments = [];
1255+
$namedArguments = [];
1256+
1257+
foreach ($testArguments as $key => $value) {
1258+
if (is_int($key)) {
1259+
$positionalArguments[] = $value;
1260+
} else {
1261+
$namedArguments[$key] = $value;
1262+
}
1263+
}
1264+
1265+
$capture = tmpfile();
1266+
$errorLogPrevious = ini_set('error_log', stream_get_meta_data($capture)['uri']);
1267+
1268+
try {
1269+
/** @phpstan-ignore method.dynamicName */
1270+
$testResult = $this->{$this->methodName}(...$namedArguments, ...$positionalArguments);
1271+
1272+
$errorLogOutput = stream_get_contents($capture);
1273+
1274+
if ($this->expectErrorLog) {
1275+
$this->assertNotEmpty($errorLogOutput, 'Test did not call error_log().');
1276+
} else {
1277+
// strip date from logged error, see https://github.com/php/php-src/blob/c696087e323263e941774ebbf902ac249774ec9f/main/main.c#L905
1278+
print preg_replace('/\[.+\] /', '', $errorLogOutput);
1279+
}
1280+
} catch (Throwable $exception) {
1281+
if (!$this->shouldExceptionExpectationsBeVerified($exception)) {
1282+
throw $exception;
1283+
}
1284+
1285+
$this->verifyExceptionExpectations($exception);
1286+
1287+
return null;
1288+
} finally {
1289+
if ($capture !== false) {
1290+
fclose($capture);
1291+
}
1292+
1293+
ini_set('error_log', $errorLogPrevious);
1294+
}
1295+
1296+
$this->expectedExceptionWasNotRaised();
1297+
1298+
return $testResult;
1299+
}
1300+
12931301
/**
12941302
* @throws ExpectationFailedException
12951303
*/

tests/end-to-end/data-provider/dependency-result.phpt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@ PHPUnit %s by Sebastian Bergmann and contributors.
1313

1414
Runtime: %s
1515

16-
...E 4 / 4 (100%)
16+
.... 4 / 4 (100%)
1717

1818
Time: %s, Memory: %s
1919

20-
There was 1 error:
20+
OK (4 tests, 7 assertions)
2121

22-
1) PHPUnit\TestFixture\DataProviderDependencyResultTest::testAdd with data set #2 (2, 0)
23-
Error: Cannot use positional argument after named argument during unpacking
24-
25-
ERRORS!
26-
Tests: 4, Assertions: 5, Errors: 1.

tests/unit/Framework/TestCaseTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
use function sprintf;
1313
use PHPUnit\Framework\Attributes\CoversClass;
14+
use PHPUnit\Framework\Attributes\DataProvider;
15+
use PHPUnit\Framework\Attributes\Depends;
1416
use PHPUnit\Framework\Attributes\ExcludeGlobalVariableFromBackup;
1517
use PHPUnit\TestFixture\TestWithDifferentNames;
1618

@@ -21,6 +23,18 @@ class TestCaseTest extends TestCase
2123
{
2224
protected static int $testStatic = 456;
2325

26+
/**
27+
* @return array<non-empty-string, array<non-empty-string, string>>
28+
*/
29+
public static function provider(): array
30+
{
31+
return [
32+
'case 1' => [
33+
'fromProvider' => 'value from provider',
34+
],
35+
];
36+
}
37+
2438
public static function setUpBeforeClass(): void
2539
{
2640
$GLOBALS['a'] = 'a';
@@ -83,4 +97,19 @@ public function testGetNameReturnsMethodName(): void
8397

8498
$this->assertSame($methodName, $testCase->nameWithDataSet());
8599
}
100+
101+
public function testDependedUponTest(): string
102+
{
103+
$this->assertTrue(true);
104+
105+
return 'value from depended-upon test';
106+
}
107+
108+
#[DataProvider('provider')]
109+
#[Depends('testDependedUponTest')]
110+
public function testTestDataFromProviderAndDependedUponTest(string $fromProvider, string $fromDependency): void
111+
{
112+
$this->assertSame('value from provider', $fromProvider);
113+
$this->assertSame('value from depended-upon test', $fromDependency);
114+
}
86115
}

0 commit comments

Comments
 (0)