Skip to content

Commit

Permalink
Closes #5616
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Dec 16, 2023
1 parent e604b33 commit 5d04989
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 5 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-10.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

## [10.5.4] - 2023-MM-DD

### Fixed

* [#5616](https://github.com/sebastianbergmann/phpunit/issues/5616): Values from data provider are not shown for failed test

## [10.5.3] - 2023-12-13

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

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

[10.5.4]: https://github.com/sebastianbergmann/phpunit/compare/10.5.3...10.5
[10.5.3]: https://github.com/sebastianbergmann/phpunit/compare/10.5.2...10.5.3
[10.5.2]: https://github.com/sebastianbergmann/phpunit/compare/10.5.1...10.5.2
[10.5.1]: https://github.com/sebastianbergmann/phpunit/compare/10.5.0...10.5.1
Expand Down
18 changes: 14 additions & 4 deletions src/Event/Value/Test/TestData/DataFromDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
final class DataFromDataProvider extends TestData
{
private readonly int|string $dataSetName;
private readonly string $dataAsStringForResultOutput;

public static function from(int|string $dataSetName, string $data): self
public static function from(int|string $dataSetName, string $data, string $dataAsStringForResultOutput): self
{
return new self($dataSetName, $data);
return new self($dataSetName, $data, $dataAsStringForResultOutput);
}

protected function __construct(int|string $dataSetName, string $data)
protected function __construct(int|string $dataSetName, string $data, string $dataAsStringForResultOutput)
{
$this->dataSetName = $dataSetName;
$this->dataSetName = $dataSetName;
$this->dataAsStringForResultOutput = $dataAsStringForResultOutput;

parent::__construct($data);
}
Expand All @@ -35,6 +37,14 @@ public function dataSetName(): int|string
return $this->dataSetName;
}

/**
* @internal This method is not covered by the backward compatibility promise for PHPUnit
*/
public function dataAsStringForResultOutput(): string
{
return $this->dataAsStringForResultOutput;
}

/**
* @psalm-assert-if-true DataFromDataProvider $this
*/
Expand Down
1 change: 1 addition & 0 deletions src/Event/Value/Test/TestMethodBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private static function dataFor(TestCase $testCase): TestDataCollection
$testData[] = DataFromDataProvider::from(
$dataSetName,
Exporter::export($testCase->providedData(), EventFacade::emitter()->exportsObjects()),
$testCase->dataSetAsStringWithData(),
);
}

Expand Down
6 changes: 5 additions & 1 deletion src/TextUI/Output/Default/ResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,11 @@ private function name(Test $test): string
if ($test->isTestMethod()) {
assert($test instanceof TestMethod);

return $test->nameWithClass();
if (!$test->testData()->hasDataFromDataProvider()) {
return $test->nameWithClass();
}

return $test->className() . '::' . $test->methodName() . $test->testData()->dataFromDataProvider()->dataAsStringForResultOutput();
}

return $test->name();
Expand Down
28 changes: 28 additions & 0 deletions tests/end-to-end/regression/5616.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/5616
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/5616/Issue5616Test.php';

require_once __DIR__ . '/../../bootstrap.php';
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

F 1 / 1 (100%)

Time: %s, Memory: %s MB

There was 1 failure:

1) PHPUnit\TestFixture\Issue5616\Issue5616Test::testOne with data set #0 (1, '2', 3.0, true)
Failed asserting that false is true.

%sIssue5616Test.php:%d

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
29 changes: 29 additions & 0 deletions tests/end-to-end/regression/5616/Issue5616Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Issue5616;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class Issue5616Test extends TestCase
{
public static function provider(): array
{
return [
[1, '2', 3.0, true],
];
}

#[DataProvider('provider')]
public function testOne(int $a, string $b, float $c, bool $d): void
{
$this->assertTrue(false);
}
}
6 changes: 6 additions & 0 deletions tests/unit/Event/Value/Test/TestMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function testNameReturnsNameWhenTestHasDataFromDataProviderAndDataSetName
DataFromDataProvider::from(
$dataSetName,
'data',
'data as string for result output',
),
],
),
Expand All @@ -99,6 +100,8 @@ public function testNameReturnsNameWhenTestHasDataFromDataProviderAndDataSetName

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

public function testNameReturnsNameWhenTestHasDataFromDataProviderAndDataSetNameIsString(): void
Expand All @@ -117,6 +120,7 @@ public function testNameReturnsNameWhenTestHasDataFromDataProviderAndDataSetName
DataFromDataProvider::from(
$dataSetName,
'data',
'data as string for result output',
),
],
),
Expand All @@ -130,5 +134,7 @@ public function testNameReturnsNameWhenTestHasDataFromDataProviderAndDataSetName

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

0 comments on commit 5d04989

Please sign in to comment.