Skip to content

Commit ca239c1

Browse files
Closes #5097
1 parent 2d4f3da commit ca239c1

9 files changed

+37
-17
lines changed

ChangeLog-10.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ All notable changes of the PHPUnit 10.0 release series are documented in this fi
1313
* [#4818](https://github.com/sebastianbergmann/phpunit/pull/4818): `assertIsList()`
1414
* [#4892](https://github.com/sebastianbergmann/phpunit/issues/4892): Make colors used in HTML code coverage report configurable
1515
* [#4893](https://github.com/sebastianbergmann/phpunit/issues/4893): Make path to custom.css for HTML code coverage report configurable
16+
* [#5097](https://github.com/sebastianbergmann/phpunit/issues/5097): Support for `enum` values in TestDox placeholder replacements
1617
* `#[ExcludeGlobalVariableFromBackup('variable')]` attribute for excluding a global variable from the backup/restore of global and super-global variables
1718
* `#[ExcludeStaticPropertyFromBackup('className', 'propertyName')]` attribute for excluding a static property from the backup/restore of static properties in user-defined classes
1819
* `--log-events-text <file>` option that controls streaming of event information (without event telemetry) in text format to a file

src/Logging/TestDox/NamePrettifier.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ private function mapTestMethodParameterNamesToProvidedDataValues(TestCase $test,
240240
if (is_object($value)) {
241241
$reflector = new ReflectionObject($value);
242242

243-
if ($reflector->hasMethod('__toString')) {
243+
if ($reflector->isEnum()) {
244+
$value = $value->value;
245+
} elseif ($reflector->hasMethod('__toString')) {
244246
$value = (string) $value;
245247
} else {
246248
$value = $value::class;

tests/end-to-end/testdox/_files/DataProviderWithNumericDataSetNameAndMetadataWithPlaceholdersTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ final class DataProviderWithNumericDataSetNameAndMetadataWithPlaceholdersTest ex
1919
/**
2020
* @dataProvider provider
2121
*
22-
* @testdox Text from method-level TestDox metadata for successful test with placeholders ($a, $b, $c $d, $e)
22+
* @testdox Text from method-level TestDox metadata for successful test with placeholders ($a, $b, $c $d, $e, $f)
2323
*/
24-
public function testSomethingThatWorks(string $a, int $b, float $c, array $d, bool $e): void
24+
public function testSomethingThatWorks(string $a, int $b, float $c, array $d, bool $e, Foo $f): void
2525
{
2626
$this->assertTrue(true);
2727
}
2828

2929
/**
3030
* @dataProvider provider
3131
*
32-
* @testdox Text from method-level TestDox metadata for failing test with placeholders ($a, $b, $c $d, $e)
32+
* @testdox Text from method-level TestDox metadata for failing test with placeholders ($a, $b, $c $d, $e, $f)
3333
*/
34-
public function testSomethingThatDoesNotWork(string $a, int $b, float $c, array $d, bool $e): void
34+
public function testSomethingThatDoesNotWork(string $a, int $b, float $c, array $d, bool $e, Foo $f): void
3535
{
3636
/* @noinspection PhpUnitAssertTrueWithIncompatibleTypeArgumentInspection */
3737
$this->assertTrue(false);
@@ -46,6 +46,7 @@ public function provider(): array
4646
0.0,
4747
['key' => 'value'],
4848
true,
49+
Foo::BAR,
4950
],
5051
];
5152
}

tests/end-to-end/testdox/_files/DataProviderWithStringDataSetNameAndMetadataWithPlaceholdersTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ final class DataProviderWithStringDataSetNameAndMetadataWithPlaceholdersTest ext
1919
/**
2020
* @dataProvider provider
2121
*
22-
* @testdox Text from method-level TestDox metadata for successful test with placeholders ($a, $b, $c $d, $e)
22+
* @testdox Text from method-level TestDox metadata for successful test with placeholders ($a, $b, $c $d, $e, $f)
2323
*/
24-
public function testSomethingThatWorks(string $a, int $b, float $c, array $d, bool $e): void
24+
public function testSomethingThatWorks(string $a, int $b, float $c, array $d, bool $e, Foo $f): void
2525
{
2626
$this->assertTrue(true);
2727
}
2828

2929
/**
3030
* @dataProvider provider
3131
*
32-
* @testdox Text from method-level TestDox metadata for failing test with placeholders ($a, $b, $c $d, $e)
32+
* @testdox Text from method-level TestDox metadata for failing test with placeholders ($a, $b, $c $d, $e, $f)
3333
*/
34-
public function testSomethingThatDoesNotWork(string $a, int $b, float $c, array $d, bool $e): void
34+
public function testSomethingThatDoesNotWork(string $a, int $b, float $c, array $d, bool $e, Foo $f): void
3535
{
3636
/* @noinspection PhpUnitAssertTrueWithIncompatibleTypeArgumentInspection */
3737
$this->assertTrue(false);
@@ -46,6 +46,7 @@ public function provider(): array
4646
0.0,
4747
['key' => 'value'],
4848
true,
49+
Foo::BAR,
4950
],
5051
];
5152
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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\TestDox;
11+
12+
enum Foo: string
13+
{
14+
case BAR = 'bar';
15+
}

tests/end-to-end/testdox/metadata-with-placeholders-data-provider-with-numeric-data-set-name-colorized.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Runtime: %s
2020
Time: %s, Memory: %s
2121

2222
Text from class-level TestDox metadata
23-
[32m ✔ [0mText from method-level TestDox metadata for successful test with placeholders ([36mstring[0m, [36m0[0m, [36m0.0[0m [36marray[0m, [36mtrue[0m)
24-
[31m ✘ [0mText from method-level TestDox metadata for failing test with placeholders ([36mstring[0m, [36m0[0m, [36m0.0[0m [36marray[0m, [36mtrue[0m)
23+
[32m ✔ [0mText from method-level TestDox metadata for successful test with placeholders ([36mstring[0m, [36m0[0m, [36m0.0[0m [36marray[0m, [36mtrue[0m, [36mbar[0m)
24+
[31m ✘ [0mText from method-level TestDox metadata for failing test with placeholders ([36mstring[0m, [36m0[0m, [36m0.0[0m [36marray[0m, [36mtrue[0m, [36mbar[0m)
2525
┐
2626
├ Failed asserting that false is true.
2727
│

tests/end-to-end/testdox/metadata-with-placeholders-data-provider-with-numeric-data-set-name.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Runtime: %s
2020
Time: %s, Memory: %s
2121

2222
Text from class-level TestDox metadata
23-
✔ Text from method-level TestDox metadata for successful test with placeholders (string, 0, 0.0 array, true)
24-
✘ Text from method-level TestDox metadata for failing test with placeholders (string, 0, 0.0 array, true)
23+
✔ Text from method-level TestDox metadata for successful test with placeholders (string, 0, 0.0 array, true, bar)
24+
✘ Text from method-level TestDox metadata for failing test with placeholders (string, 0, 0.0 array, true, bar)
2525
2626
│ Failed asserting that false is true.
2727

tests/end-to-end/testdox/metadata-with-placeholders-data-provider-with-string-data-set-name-colorized.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Runtime: %s
2020
Time: %s, Memory: %s
2121

2222
Text from class-level TestDox metadata
23-
[32m ✔ [0mText from method-level TestDox metadata for successful test with placeholders ([36mstring[0m, [36m0[0m, [36m0.0[0m [36marray[0m, [36mtrue[0m)
24-
[31m ✘ [0mText from method-level TestDox metadata for failing test with placeholders ([36mstring[0m, [36m0[0m, [36m0.0[0m [36marray[0m, [36mtrue[0m)
23+
[32m ✔ [0mText from method-level TestDox metadata for successful test with placeholders ([36mstring[0m, [36m0[0m, [36m0.0[0m [36marray[0m, [36mtrue[0m, [36mbar[0m)
24+
[31m ✘ [0mText from method-level TestDox metadata for failing test with placeholders ([36mstring[0m, [36m0[0m, [36m0.0[0m [36marray[0m, [36mtrue[0m, [36mbar[0m)
2525
┐
2626
├ Failed asserting that false is true.
2727
│

tests/end-to-end/testdox/metadata-with-placeholders-data-provider-with-string-data-set-name.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Runtime: %s
2020
Time: %s, Memory: %s
2121

2222
Text from class-level TestDox metadata
23-
✔ Text from method-level TestDox metadata for successful test with placeholders (string, 0, 0.0 array, true)
24-
✘ Text from method-level TestDox metadata for failing test with placeholders (string, 0, 0.0 array, true)
23+
✔ Text from method-level TestDox metadata for successful test with placeholders (string, 0, 0.0 array, true, bar)
24+
✘ Text from method-level TestDox metadata for failing test with placeholders (string, 0, 0.0 array, true, bar)
2525
2626
│ Failed asserting that false is true.
2727

0 commit comments

Comments
 (0)