mikeerickson / phpunit-pretty-result-printer

PHPUnit Pretty Result Printer -- make your PHPUnit tests look pretty!
MIT License
1.2k stars 71 forks source link

Setting a custom message for an assertion throws an error #148

Closed nesk closed 5 years ago

nesk commented 5 years ago

When setting a custom message for an assertion, the printer throws an exception.

Here's an example:

self::assertEquals(1, 2, 'My custom message.');

The code fails at this line with the following error:

sprintf(): Too few arguments

This is because the $exceptionMessage variable contains two directives instead of one, here's the content of the variable with the example above:

"   %My custom message.
 %sFailed asserting that 2 matches expected 1.
"

We have two %s directives instead of one, thus the sprintf() function fails.

mikeerickson commented 5 years ago

@nesk Thank you for the report, I will have a look. In the meantime, PRs are welcome 👍

mikeerickson commented 5 years ago

@nesk I have just tried this agains the current release 0.26.1 and it works as expected?

Here is my test case


<?php

use \PHPUnit\Framework\TestCase;

class CustomAssertMessage extends TestCase
{
    /*
     * @group xxx
     */
    public function test_custom_message()
    {
        $this->assertEquals(1,2,"This is a test message");
    }
}

Output appears as expected

image

nesk commented 5 years ago

Sorry, just tried to reproduce this in a new and dedicated project, but I can't manage to do it.

This issue is probably on me. 😓