Skip to content

Commit 5d04989

Browse files
Closes #5616
1 parent e604b33 commit 5d04989

File tree

7 files changed

+90
-5
lines changed

7 files changed

+90
-5
lines changed

ChangeLog-10.5.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 10.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [10.5.4] - 2023-MM-DD
6+
7+
### Fixed
8+
9+
* [#5616](https://github.com/sebastianbergmann/phpunit/issues/5616): Values from data provider are not shown for failed test
10+
511
## [10.5.3] - 2023-12-13
612

713
### Deprecated
@@ -45,6 +51,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi
4551

4652
* [#5563](https://github.com/sebastianbergmann/phpunit/issues/5563): `createMockForIntersectionOfInterfaces()` does not automatically register mock object for expectation verification
4753

54+
[10.5.4]: https://github.com/sebastianbergmann/phpunit/compare/10.5.3...10.5
4855
[10.5.3]: https://github.com/sebastianbergmann/phpunit/compare/10.5.2...10.5.3
4956
[10.5.2]: https://github.com/sebastianbergmann/phpunit/compare/10.5.1...10.5.2
5057
[10.5.1]: https://github.com/sebastianbergmann/phpunit/compare/10.5.0...10.5.1

src/Event/Value/Test/TestData/DataFromDataProvider.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
final class DataFromDataProvider extends TestData
1818
{
1919
private readonly int|string $dataSetName;
20+
private readonly string $dataAsStringForResultOutput;
2021

21-
public static function from(int|string $dataSetName, string $data): self
22+
public static function from(int|string $dataSetName, string $data, string $dataAsStringForResultOutput): self
2223
{
23-
return new self($dataSetName, $data);
24+
return new self($dataSetName, $data, $dataAsStringForResultOutput);
2425
}
2526

26-
protected function __construct(int|string $dataSetName, string $data)
27+
protected function __construct(int|string $dataSetName, string $data, string $dataAsStringForResultOutput)
2728
{
28-
$this->dataSetName = $dataSetName;
29+
$this->dataSetName = $dataSetName;
30+
$this->dataAsStringForResultOutput = $dataAsStringForResultOutput;
2931

3032
parent::__construct($data);
3133
}
@@ -35,6 +37,14 @@ public function dataSetName(): int|string
3537
return $this->dataSetName;
3638
}
3739

40+
/**
41+
* @internal This method is not covered by the backward compatibility promise for PHPUnit
42+
*/
43+
public function dataAsStringForResultOutput(): string
44+
{
45+
return $this->dataAsStringForResultOutput;
46+
}
47+
3848
/**
3949
* @psalm-assert-if-true DataFromDataProvider $this
4050
*/

src/Event/Value/Test/TestMethodBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ private static function dataFor(TestCase $testCase): TestDataCollection
8080
$testData[] = DataFromDataProvider::from(
8181
$dataSetName,
8282
Exporter::export($testCase->providedData(), EventFacade::emitter()->exportsObjects()),
83+
$testCase->dataSetAsStringWithData(),
8384
);
8485
}
8586

src/TextUI/Output/Default/ResultPrinter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,11 @@ private function name(Test $test): string
515515
if ($test->isTestMethod()) {
516516
assert($test instanceof TestMethod);
517517

518-
return $test->nameWithClass();
518+
if (!$test->testData()->hasDataFromDataProvider()) {
519+
return $test->nameWithClass();
520+
}
521+
522+
return $test->className() . '::' . $test->methodName() . $test->testData()->dataFromDataProvider()->dataAsStringForResultOutput();
519523
}
520524

521525
return $test->name();

tests/end-to-end/regression/5616.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/5616
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/5616/Issue5616Test.php';
8+
9+
require_once __DIR__ . '/../../bootstrap.php';
10+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
11+
--EXPECTF--
12+
PHPUnit %s by Sebastian Bergmann and contributors.
13+
14+
Runtime: %s
15+
16+
F 1 / 1 (100%)
17+
18+
Time: %s, Memory: %s MB
19+
20+
There was 1 failure:
21+
22+
1) PHPUnit\TestFixture\Issue5616\Issue5616Test::testOne with data set #0 (1, '2', 3.0, true)
23+
Failed asserting that false is true.
24+
25+
%sIssue5616Test.php:%d
26+
27+
FAILURES!
28+
Tests: 1, Assertions: 1, Failures: 1.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Issue5616;
11+
12+
use PHPUnit\Framework\Attributes\DataProvider;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class Issue5616Test extends TestCase
16+
{
17+
public static function provider(): array
18+
{
19+
return [
20+
[1, '2', 3.0, true],
21+
];
22+
}
23+
24+
#[DataProvider('provider')]
25+
public function testOne(int $a, string $b, float $c, bool $d): void
26+
{
27+
$this->assertTrue(false);
28+
}
29+
}

tests/unit/Event/Value/Test/TestMethodTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function testNameReturnsNameWhenTestHasDataFromDataProviderAndDataSetName
8686
DataFromDataProvider::from(
8787
$dataSetName,
8888
'data',
89+
'data as string for result output',
8990
),
9091
],
9192
),
@@ -99,6 +100,8 @@ public function testNameReturnsNameWhenTestHasDataFromDataProviderAndDataSetName
99100

100101
$this->assertSame($expected, $test->name());
101102
$this->assertSame('FooTest::testBar#9000', $test->id());
103+
$this->assertSame('data', $test->testData()->dataFromDataProvider()->data());
104+
$this->assertSame('data as string for result output', $test->testData()->dataFromDataProvider()->dataAsStringForResultOutput());
102105
}
103106

104107
public function testNameReturnsNameWhenTestHasDataFromDataProviderAndDataSetNameIsString(): void
@@ -117,6 +120,7 @@ public function testNameReturnsNameWhenTestHasDataFromDataProviderAndDataSetName
117120
DataFromDataProvider::from(
118121
$dataSetName,
119122
'data',
123+
'data as string for result output',
120124
),
121125
],
122126
),
@@ -130,5 +134,7 @@ public function testNameReturnsNameWhenTestHasDataFromDataProviderAndDataSetName
130134

131135
$this->assertSame($expected, $test->name());
132136
$this->assertSame('FooTest::testBar#bar-9000', $test->id());
137+
$this->assertSame('data', $test->testData()->dataFromDataProvider()->data());
138+
$this->assertSame('data as string for result output', $test->testData()->dataFromDataProvider()->dataAsStringForResultOutput());
133139
}
134140
}

0 commit comments

Comments
 (0)