Fix ArgumentCountError in ReportPrinter when test names contain % characters#6927
Conversation
…ause ArgumentCountError Signed-off-by: Benjamin Fahl <git@fahl-design.de>
…ArgumentCountError Signed-off-by: Benjamin Fahl <git@fahl-design.de>
|
hey @burned42 , can you please review and merge this anytime soon? It's just a small fix with tests to verify ✌️ |
|
@Fahl-Design I can take a look, sure, but my review does not necessarily help move this PR forward as I don't have any permissions in this repo 😅 Generally the PR looks fine to me. Having actual assertions instead of the dummy "true === true" check would be nice, but I'm not sure if that's possible. There's only one thing I don't yet understand and that's the double-escape prevention. In case the test name contains |
Oh sorry^^ and thanks anyway to take a look at it. Somehow i mixed up the names. I think I got all '%' cases now, I'm still surprised that nobody ran into this before, maybe not many use dataProvider with % in case name and than use the "--report" flag
maybe @TavoNiievez can help to get this merged |
Description
This PR fixes a bug in
Codeception\Reporter\ReportPrinterwhere anArgumentCountErroris thrown if a test name contains a percent character (%), and the test suite is executed with the--reportflag.Root Cause
ReportPrinter->printTestResult()retrieves the test name and passes it directly to$this->message(), which internally acts as a wrapper forsprintf(...func_get_args()). When a test name contains%(e.g., from a DataProvider outputting"100% coverage"or"test with %s"),sprintftries to interpret it as a format specifier. Since no additional arguments are passed, it panics and throws a fatalArgumentCountError.Solution
Before passing the test name into
$this->message(), any lone%character is properly escaped to%%. This tellssprintfto treat the percent sign as a literal string character rather than a formatting placeholder. To prevent double-escaping (if the test name somehow already contained%%), the logic safely converts%%back to%before escaping them.Testing
A new comprehensive test suite
tests/unit/Codeception/Reporter/ReportPrinterTest.phphas been added.Using a
@dataProvider, it successfully verifies the correct escaping behavior for:'testWith100%Coverage''%''there are %%% from %%% cases solved''string with %s format',%d,%f,%x, etc.Test Command Run:
All tests pass successfully.
(bug found and fixed by human (me), reviewed, tests written and pr text by Gemini 3.1 Pro)