1

I want to know the most robust way of checking for PHP error messages when running automated tests that interact with a PHP application via a browser emulator.

The reason is: I use Behat, Mink and Selenium/Webkit/etc to test my PHP applications in the following ways:

  • as acceptance tests, to make sure expected functionality exists
  • as end-to-end tests, to test success of complete integration

And so it seems obvious to me that most tests run by Behat/Mink should additionally parse the pages they do tests on for PHP errors, warnings, notices etc, as a matter of course.

But, it's not easy, for a number of reasons:

  1. The server that the PHP application is running on may output errors differently, depending on factors such as whether XDebug is used.
  2. On a production server, errors, warnings and so on would not be output at all.

AFAIK, nothing can be done about point 2? So if I wanted my behat test results regarding parsing for PHP errors to be meaningful, it would have to be done on a server where the configuration is to display errors.

But regarding point 1, I have a simple idea for how to achieve it: explicitly use error and exception handlers within the PHP application so if/when they are output, they will be in a format that can be easily parsed and tested for.

It seems like a reasonable idea, yet has a bad smell about it. So I would like to know if:

  1. There is another way of more robustly looking for errors in end-to-end tests
  2. I am going about this whole thing in the wrong way.
Jodes
  • 839
  • 6
  • 12
  • 1
    I usually configure the PHP server not to output error/warning messages, but to log them. You don't need to create your own error handling for this because it is a built-in option. – Brandin Sep 19 '15 at 22:51
  • So I should have the Behat tests delve into the server's logs each time it wants to check if a page had errors? It would really make the tests run slowly if the server's not on localhost – Jodes Sep 21 '15 at 07:46
  • Not the server logs. Use a specific log file for your application, then your test script can just look at that file. Look here for example http://stackoverflow.com/questions/3531703/how-to-log-errors-and-warnings-into-a-file – Brandin Sep 21 '15 at 10:10

0 Answers0