sectus
sectus

Reputation: 15464

How to catch php errors which occurs while Selenium PHPUnit test running?

I am using apache2, Selenium, PHPUnit.

Some tests cause php errors but passed because it looks like everything is good from browser.

How can I catch those errors to mark test as failed?

Upvotes: 2

Views: 984

Answers (2)

Madara's Ghost
Madara's Ghost

Reputation: 175098

The best way would be to make PHP throw ErrorExceptions on error.

set_error_handler(
    function($err_severity, $err_msg, $err_file, $err_line) { 
        throw new ErrorException($err_msg, 0, $err_severity, $err_file, $err_line) 
    }
);

Since an error is always fatal, the test will fail by default when an error occurs (note that it would halt the rest of the test if you don't assert/catch the exception).

Upvotes: 1

Sven
Sven

Reputation: 70933

PHPUnit allows to add checks that are run before or after every test function. Just add a assertPreConditions() or assertPostConditions() to your test to see if there are traces of PHP failure.

See http://phpunit.de/manual/3.7/en/fixtures.html for some more details.

Now the question is: How to detect these errors? Either check if there are error texts on the screen, or (if you run local to the apache) check if the php error log file has increased in size - it should not. This highly depends on your needs.

Upvotes: 0

Related Questions