Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
fredericgboutin-yapla opened this issue Aug 21, 2024 · 3 comments · Fixed by #5940
Labels
feature/data-provider Data Providers feature/testdox The TextDox printer/formatter type/bug Something is broken

Comments

@fredericgboutin-yapla
Copy link

fredericgboutin-yapla commented Aug 21, 2024

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
@fredericgboutin-yapla fredericgboutin-yapla added the type/bug Something is broken label Aug 21, 2024
@sebastianbergmann sebastianbergmann added feature/testdox The TextDox printer/formatter feature/data-provider Data Providers labels Aug 22, 2024
@fredericgboutin-yapla fredericgboutin-yapla changed the title Testdox output containing dollar signs at the beginning gets truncated when used with a data provided Testdox output containing dollar signs at the beginning gets truncated when used with a data provider Aug 23, 2024
@sebastianbergmann sebastianbergmann changed the title Testdox output containing dollar signs at the beginning gets truncated when used with a data provider TestDox output containing $ at the beginning gets truncated when used with a data provider Sep 6, 2024
@fredericgboutin-yapla
Copy link
Author

Thank you @sebastianbergmann, you are the GOAT.

@sebastianbergmann
Copy link
Owner

I do not know what "you are the GOAT" means, but I hope that it is something nice. Anyway, @kubawerlos fixed the issue ... so maybe he is the GOAT?

@fredericgboutin-yapla
Copy link
Author

I meant "Greatest Of All Time" 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/data-provider Data Providers feature/testdox The TextDox printer/formatter type/bug Something is broken
Projects
None yet
2 participants