Parris Varney
Parris Varney

Reputation: 11478

How to force a failure with phpunit

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

Upvotes: 79

Views: 23803

Answers (3)

Jannie Theunissen
Jannie Theunissen

Reputation: 30074

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.");
}

Upvotes: 3

Arpan Buch
Arpan Buch

Reputation: 1400

Yes, theres a way,

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

if you want to see the page u have failed than

print_r(getResponse()->getContent());

Upvotes: 4

rr.
rr.

Reputation: 6644

I believe this should work within a test case:

$this->fail('Message');

Upvotes: 126

Related Questions