简体   繁体   English

Simpletest无法重新声明simpletest_autorun()

[英]Simpletest Cannot redeclare simpletest_autorun()

A Simpletest test in MyTest.php that runs with no errors: 在MyTest.php中运行的Simpletest测试没有错误:

require_once ('simpletest/autorun.php');

class MyTest extends UnitTestCase {
    function test() {
        //Test...
    }
}

A SimpleTest test suite 一个SimpleTest测试套件

require_once ('simpletest/autorun.php');
class AllTests extends TestSuite {
    function __construct() {
        $this->TestSuite('All tests');
        $this->addFile('MyTest.php');
    }
}

The error: 错误:

Fatal error: Cannot redeclare simpletest_autorun() (previously declared in /Library/WebServer/Documents/Option/tests/simpletest/autorun.php:26) in /Library/WebServer/Documents/option/tests/simpletest/autorun.php on line 34 致命错误:无法在/Library/WebServer/Documents/options/tests/simpletest/autorun.php中重新声明/Library/WebServer/Documents/options/tests/simpletest/autorun.php中的simpletest_autorun()(先前在/Library/WebServer/Documents/Options/tests/simpletest/autorun.php:26中声明) 34

The (horrible) solution, change MyTest.php to: (可怕的)解决方案,将MyTest.php更改为:

if (!function_exists("simpletest_autorun")) {
    require_once ('simpletest/autorun.php');
}
class MyTest extends UnitTestCase {
    function test() {
        //Test...
    }
}   

It appears that this example follows the documentation, it doesn't or SimpleTest has this bug? 看来此示例遵循了文档,不是吗或SimpleTest是否存在此错误?

I can only assume you have multiple copies of the SimpleTest autorun.php script. 我只能假设您有SimpleTest autorun.php脚本的多个副本。

Performing the require in your test case file attempts to include a second autorun.php file (different to the one included in your test suite) which defines simpletest_autorun() for the second time. 在测试用例文件中执行require尝试包括第二个autorun.php文件(与测试套件中包含的文件不同simpletest_autorun() ,该文件第二次定义了simpletest_autorun()

The fact that the line numbers don't match up adds credence to my assumption. 行号不匹配的事实增加了我的假设的可信度。

Looking at the full paths in the error messages should show you what's up. 查看错误消息中的完整路径 ,应该可以告诉您最新情况。

Determine which copy you want to keep and remove the other, updating any incorrect paths in your code or configuration, including the include_path in php.ini . 确定要保留的副本并删除另一个副本,更新代码或配置中的所有不正确路径,包括php.iniinclude_path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM