Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit, Selenium Basic Test Fails with Fatal Error

I am running PHP 5.3.6 and the latest version of PHPUnit from Github. When I copy example 17.1 from the docs, it suffers a fatal error when the assertTitle fails. I get this error message:

Fatal error: Call to a member function toString() on a non-object in <path>/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumTestCase.php on line 1041

When I change the assertion to pass, PHPUnit runs just fine.

I dug up the line and this is the snippet :

protected function onNotSuccessfulTest(Exception $e)
    {
        if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
            $buffer  = 'Current URL: ' . $this->drivers[0]->getLocation() .
                       "\n";
            $message = $e->getComparisonFailure()->toString();

$e->getComparisonFailure() returns NULL, not an object. What am I doing incorrectly?

UPDATE:

I found the reason for the failure, although a fix isn't on my horizon yet.

On line 92 of PHPUnit/Framework/Constraint.php, it calls using

$this->fail($other,$description)

which is defined as:

protected function fail($other, $description, PHPUnit_Framework_ComparisonFailure $comparisonFailure = NULL)

Since no PHPUnit_Framework_ComparisonFailure is passed, NULL is passed on line 141 of PHPUnit/Framework/Constraint.php

 

throw new PHPUnit_Framework_ExpectationFailedException(           $failureDescription,           $comparisonFailure         );

which is fetched by getComparisonFailure() which is supposed to return an object, as described above.

Any more ideas?

like image 440
Eric Cope Avatar asked Jan 23 '26 07:01

Eric Cope


1 Answers

Just replace $message = $e->getComparisonFailure()->toString(); with $message = $e->getComparisonFailure()->exceptionToString;

It works fine for me

like image 129
Klaidi Avatar answered Jan 24 '26 23:01

Klaidi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!