phpunit
phpunit copied to clipboard
Testdox output containing dollar signs at the beginning gets truncated when used with a data provider
Q | A |
---|---|
PHPUnit version | 10.5.30 |
PHP version | 8.2.21 |
Installation Method | Composer |
Summary
Except if I'm mistaken, I see no way to properly escape a dollar sign $
at the beginning of an argument's value from a data provider when used with testdox output.
The problem exists for both annotations and attributes.
Current behavior
The referred variable's value gets truncated in testdox output.
How to reproduce
public static function myDataProvider()
{
return [
['$12.34']
];
}
/**
* @testdox testdox should output $12.34 instead of $myValue
*
* @dataProvider myDataProvider
*/
public function testTestDoxAnnotation(string $myValue)
{
$this->assertEquals('$12.34', $myValue);
}
#[\PHPUnit\Framework\Attributes\TestDox('testdox should output $12.34 instead of $myValue')]
#[\PHPUnit\Framework\Attributes\DataProvider('myDataProvider')]
public function testTestDoxAttribute(string $myValue)
{
$this->assertEquals('$12.34', $myValue);
}
The testdox output reads,
✔ testdox should output $12.34 instead of .34
✔ testdox should output $12.34 instead of .34
Expected behavior
✔ testdox should output $12.34 instead of $12.34
✔ testdox should output $12.34 instead of $12.34
"Workaround"
You can aggressively escape the dollar sign but you need to cleanup the asserted value 😞
public static function myDataProvider()
{
return [
['\$12.34']
];
}
/**
* @testdox testdox should output $12.34 instead of $myValue
*
* @dataProvider myDataProvider
*/
public function testTestDoxAnnotation(string $myValue)
{
$this->assertEquals('$12.34', str_replace('\\', '', $myValue));
}
#[\PHPUnit\Framework\Attributes\TestDox('testdox should output $12.34 instead of $myValue')]
#[\PHPUnit\Framework\Attributes\DataProvider('myDataProvider')]
public function testTestDoxAttribute(string $myValue)
{
$this->assertEquals('$12.34', str_replace('\\', '', $myValue));
}
✔ testdox should output $12.34 instead of $12.34
✔ testdox should output $12.34 instead of $12.34