PHPUnit,Selenium Basic测试失败,出现致命错误

PHPUnit,Selenium Basic测试失败,出现致命错误,php,selenium,phpunit,tostring,Php,Selenium,Phpunit,Tostring,我在Github上运行PHP5.3.6和PHPUnit的最新版本。当我从文档中复制示例17.1时,当assertTitle失败时,它会遇到一个致命错误。我收到以下错误消息: Fatal error: Call to a member function toString() on a non-object in <path>/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumTestCase.php on line 1041 $e

我在Github上运行PHP5.3.6和PHPUnit的最新版本。当我从文档中复制示例17.1时,当assertTitle失败时,它会遇到一个致命错误。我收到以下错误消息:

Fatal error: Call to a member function toString() on a non-object in <path>/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumTestCase.php on line 1041
$e->getComparisonFailure()返回NULL,而不是对象。我做错了什么

更新:

我找到了失败的原因,尽管我还没有找到解决办法

在PHPUnit/Framework/Constraint.php的第92行,它使用

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

定义为:

受保护函数失败($other,$description,PHPUnit\u Framework\u ComparisonFailure$ComparisonFailure=NULL)

由于没有传递PHPUnit\u Framework\u ComparisonFailure,因此在PHPUnit/Framework/Constraint.php的第141行上传递了
NULL

抛出新的PHPUnit\u框架\u预期失败异常( $failureDescription, $comparisonFailure         );

它由getComparisonFailure()获取,它应该返回一个对象,如上所述


还有什么想法吗?

只要替换
$message=$e->getComparisonFailure()->toString()
$message=$e->getComparisonFailure()->exceptionToString


它对我来说很好

我替换了
$message=$e->getComparisonFailure()->toString()将成为:

if($e->getComparisonFailure() == NULL)
{
    $message = $e;
}
else
{
    $message = $e->getComparisonFailure()->toString();
}
我还将PHPUnit_Framework_ExpectationFailedException恢复到3.5.3,因此它有
setCustomMessage()

这个问题与Github上的PHPUnit Selenium项目有关。我已经做出了一个承诺来解决这个问题,还有一个承诺来解决Matthew提到的问题。我认为这两个问题都是由

换到哪里

// ?: 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();
}
在onNotSuccessfulTest()的末尾:

其中更改为:

// ?: 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());
}

希望PHPUnit Selenium项目能够接受这两项变更。至少它修复了我在PEAR中最新更新PHPUnit和PHPUnit Selenium时遇到的问题。

您说的默认值是复制粘贴,phpunit selenium的示例有一个错误,当其中唯一的断言失败时,复制和粘贴应该失败?这对我来说不起作用,因为$e->getComparisonFailure返回的对象为NULL,而不是一个方法为“exceptionToString”的对象。我将它从exceptionToString()更改为exceptionToString,它起作用了。这是PHPUnit中需要pull请求的bug吗?
// ?: 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();
}
$e->setCustomMessage($buffer);
// ?: 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());
}