How to replace phpunit claim message?

How do I replace the assertion error message? If I call $this->assertTrue(false, 'message')

, it displays both the string "message" and another message stating that false is not correct. How can I get only the output of the message I have selected? Is it possible?

+3


source to share


3 answers


code-crutch that comes to my mind when I faced the same problem:



public function assertTrue($condition, $message = '')
{
    if (!$condition) $this->fail($message);
}

      

+1


source


As of PHPUnit 6, you must have at least one statement, so I suggest @avolkov's slightly edited answer:



public function assertTrue($condition, $message = '')
{

    if (!$condition){
      $this->fail($message); //This will cause test fail with your message
    }
    else{
      $this->anything(); //This will eliminate error which says that your test doesn't have assertion
    }
}

      

0


source


It's impossible.

Why do you need this? I've never come across a case where the default message doesn't help anything. The custom message should add information and not override the default.

-1


source







All Articles