PHPUnit,Selenium Basic测试失败,并出现致命错误 [英] PHPUnit, Selenium Basic Test Fails with Fatal Error

查看:87
本文介绍了PHPUnit,Selenium Basic测试失败,并出现致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行PHP 5.3.6和Github的最新版本的PHPUnit.当我从文档中复制示例17.1时,当assertTitle失败时,它将遭受致命错误.我收到此错误消息:

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

当我更改要传递的断言时,PHPUnit可以正常运行.

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()返回NULL,而不是对象.我做错了什么?

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

更新:

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

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

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

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

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

定义为:

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

由于未传递PHPUnit_Framework_ComparisonFailure,因此在PHPUnit/Framework/Constraint.php的第141行传递了NULL

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

抛出新的PHPUnit_Framework_ExpectationFailedException( $ failureDescription, $ comparisonFailure );

throw new PHPUnit_Framework_ExpectationFailedException(           $failureDescription,           $comparisonFailure         );

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

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

还有其他想法吗?

推荐答案

只需将$message = $e->getComparisonFailure()->toString();替换为$message = $e->getComparisonFailure()->exceptionToString;

对我来说很好

这篇关于PHPUnit,Selenium Basic测试失败,并出现致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆