Skip to content

TestDox output containing $ at the beginning gets truncated when used with a data provider #5929

@fredericgboutin-yapla

Description

@fredericgboutin-yapla
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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions