75

Is there a more official way to force a phpunit failure than $this->assertTrue(false)?

Parris Varney
  • 11,320
  • 12
  • 47
  • 76

3 Answers3

122

I believe this should work within a test case:

$this->fail('Message');
rr.
  • 6,484
  • 9
  • 40
  • 48
3

Yes, theres a way,

$this->fail("your message");

if you want to see the page u have failed than

print_r(getResponse()->getContent());
Arpan Buch
  • 1,380
  • 5
  • 19
  • 41
3

Another way to do it (especially helpful when writing a testing tool) would be:

use PHPUnit_Framework_ExpectationFailedException as PHPUnitException;

try {
    // something here
} catch (SpecificException $e) {
    // force a fail:
    throw new PHPUnitException("This was not expected.");
}
Jannie Theunissen
  • 28,256
  • 21
  • 100
  • 127