Skip to content

Bug ArgumentCountError in ReportPrinter when test names contain % characters (from Datasets keys with --report flag) #6928

@Fahl-Design

Description

@Fahl-Design

Description

This PR fixes a bug in Codeception\Reporter\ReportPrinter where an ArgumentCountError is thrown if a test name contains a percent character (%), and the test suite is executed with the --report flag.

Root Cause

ReportPrinter->printTestResult() retrieves the test name and passes it directly to $this->message(), which internally acts as a wrapper for sprintf(...func_get_args()). When a test name contains % (e.g., from a DataProvider outputting "100% coverage" or "test with %s"), sprintf tries to interpret it as a format specifier. Since no additional arguments are passed, it panics and throws a fatal ArgumentCountError.

Solution

Before passing the test name into $this->message(), any lone % character is properly escaped to %%. This tells sprintf to 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.

Fixed with MR: #6927

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions