PHPUnit, Selenium Basic Test Fails with Fatal Error
This problem relates to issue #66 on the PHPUnit-Selenium project on Github. I've made one commit that fixes this problem and one that fixes the "setCustomMessage()" problem which Matthew mentioned. I think both problems where introduced by one commit in PHPUnit 3.6
$message = $e->getComparisonFailure()->toString();
Where changed to
// ?: Is "comparison failure" set and therefore an object? (fixes issue #66)if(is_object($e->getComparisonFailure())) { // -> Comparison failure is and object and should therefore have the toString method $message = $e->getComparisonFailure()->toString();}else { // -> Comparison failure is not an object. Lets use exception message instead $message = $e->getMessage();}
And at the end of onNotSuccessfulTest():
$e->setCustomMessage($buffer);
Where changed to:
// ?: Does the setCustomMessage method exist on the exception object? (fixes issue #67)if(method_exists($e, 'setCustomMessage')) { // -> Method setCustomMessage does exist on the object, this means we are using PHPUnit // between 3.4 and 3.6 $e->setCustomMessage($buffer);}else { // -> Method setCustomerMessages does not exist on the object, must make a new exception to // add the new message (inc. current URL, screenshot path, etc) $e = new PHPUnit_Framework_ExpectationFailedException($buffer, $e->getComparisonFailure());}
Hopefully both changes will be accepted into the PHPUnit-Selenium project. At least it fixed the problems I where having with the latest updates for PHPUnit and PHPUnit-Selenium from PEAR.
I replaced $message = $e->getComparisonFailure()->toString();
to be:
if($e->getComparisonFailure() == NULL){ $message = $e;}else{ $message = $e->getComparisonFailure()->toString();}
I also reverted PHPUnit_Framework_ExpectationFailedException back to 3.5.3 so it has setCustomMessage()