1

I'm using phpunit for TDD approach. Currently, some tests I've already written fail, because I'm waiting for other people to catch up with my tests. Therefore, I want to print out a failed assertion message for each assertion that fails now, e.g.

$this->assertTrue($now_its_false, '> my friend should fix method X to return Y');

This works for standard assertions, but I can't figure out how to print such message when testing exceptions. For example, I've test a method that should raise an exception, but it doesn't. My code looks like this:

public function testSomethingIncorrect() {
  $this->setExpectedException('SomeException');
  $object->doSomethingThatShouldRaiseException();
  $this->fail('This call should raise exception!');
}

How to print out the test fail message here?

1 Answer 1

1

There is no "clear" way to achieve this. You can notice that PHPUnit_Framework_Constraint_Exception doesn't take any description argument.

Anyway you can do it "around".

try {
    $object->doSomethingThatShouldRaiseException();
    $this->fail('This call should raise exception!');
} catch ('SomeException') {

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.