Skip to content

Commit

Permalink
Closes #3270
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 5, 2018
1 parent 1bd5629 commit 533cc21
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-7.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

## [7.3.4] - 2018-MM-DD

### Fixed

* Fixed [#3270](https://github.com/sebastianbergmann/phpunit/issues/3270): Array / Object to string conversion in `NamePrettifier`

## [7.3.3] - 2018-09-01

### Fixed
Expand Down Expand Up @@ -52,6 +58,7 @@ All notable changes of the PHPUnit 7.3 release series are documented in this fil
* Fixed [#3222](https://github.com/sebastianbergmann/phpunit/pull/3222): Priority of `@covers` and `@coversNothing` is wrong
* Fixed [#3225](https://github.com/sebastianbergmann/phpunit/issues/3225): `coverage-php` missing from `phpunit.xsd`

[7.3.4]: https://github.com/sebastianbergmann/phpunit/compare/7.3.3...7.3.4
[7.3.3]: https://github.com/sebastianbergmann/phpunit/compare/7.3.2...7.3.3
[7.3.2]: https://github.com/sebastianbergmann/phpunit/compare/7.3.1...7.3.2
[7.3.1]: https://github.com/sebastianbergmann/phpunit/compare/7.3.0...7.3.1
Expand Down
23 changes: 22 additions & 1 deletion src/Util/TestDox/NamePrettifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace PHPUnit\Util\TestDox;

use PHPUnit\Framework\TestCase;
use SebastianBergmann\Exporter\Exporter;

/**
* Prettifies class and method names for use in TestDox documentation.
Expand Down Expand Up @@ -161,7 +162,27 @@ private function mapTestMethodParameterNamesToProvidedDataValues(TestCase $test)
$i = 0;

foreach ($reflector->getParameters() as $parameter) {
$providedData['$' . $parameter->getName()] = $providedDataValues[$i++];
$value = $providedDataValues[$i++];

if (\is_object($value)) {
$reflector = new \ReflectionObject($value);

if ($reflector->hasMethod('__toString')) {
$value = (string) $value;
}
}

if (!\is_scalar($value)) {
$value = \gettype($value);
}

if (\is_bool($value) || \is_numeric($value)) {
$exporter = new Exporter;

$value = $exporter->export($value);
}

$providedData['$' . $parameter->getName()] = $value;
}

return $providedData;
Expand Down
11 changes: 10 additions & 1 deletion tests/TextUI/dataprovider-testdox.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ DataProviderTestDox
✔ Does something with data set "two"
✔ Does something else with data set "one"
✔ Does something else with data set "two"
✔ ... true ...
✔ ... 1 ...
✔ ... 1.0 ...
✔ ... string ...
✔ ... array ...
✔ ... object ...
✔ ... string ...
✔ ... resource ...
✔ ... NULL ...

Time: %s, Memory: %s

OK (4 tests, 4 assertions)
OK (13 tests, 13 assertions)
29 changes: 29 additions & 0 deletions tests/_files/DataProviderTestDoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,40 @@ public function testDoesSomethingElseWith(): void
$this->assertTrue(true);
}

/**
* @dataProvider placeHolderprovider
* @testdox ... $value ...
*/
public function testWithPlaceholders($value): void
{
$this->assertTrue(true);
}

public function provider()
{
return [
'one' => [1],
'two' => [2]
];
}

public function placeHolderprovider(): array
{
return [
'boolean' => [true],
'integer' => [1],
'float' => [1.0],
'string' => ['string'],
'array' => [[1, 2, 3]],
'object' => [new \stdClass],
'stringableObject' => [new class {
public function __toString()
{
return 'string';
}
}],
'resource' => [\fopen(__FILE__, 'rb')],
'null' => [null]
];
}
}

0 comments on commit 533cc21

Please sign in to comment.