【问题标题】:Simpletest Cannot redeclare simpletest_autorun()Simpletest 无法重新声明 simpletest_autorun()
【发布时间】:2014-07-10 23:39:14
【问题描述】:

在 MyTest.php 中运行没有错误的 Simpletest 测试:

require_once ('simpletest/autorun.php');

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

一个 SimpleTest 测试套件

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

错误:

致命错误:无法在 /Library/WebServer/Documents/option/tests/simpletest/autorun 中重新声明 simpletest_autorun()(之前在 /Library/WebServer/Documents/Option/tests/simpletest/autorun.php:26 中声明)。第34行的php

(可怕的)解决方案,将 MyTest.php 更改为:

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

这个例子似乎遵循文档,它没有或 SimpleTest 有这个错误?

【问题讨论】:

  • 您在错误消息中将完整路径替换为 "dir" 所省略的信息是找出问题的关键。
  • @Phil 已更新完整目录。我认为这就是我更换的原因。更仔细地看,有一个标题“o”的区别
  • 好了。 OS X 文件系统区分大小写。
  • @Phil 但它没有解释为什么要调用不同的案例。考虑到 MyTest.php 和 AllTest.php 位于同一个目录中,调用 require_once 应该会产生不同的输出
  • 这个问题中没有足够的信息可以说明。在某处,您有一些在Option 中查找的代码和在option 中查找的一些其他代码。据我所知,甚至可以在您的include_path 中进行配置。

标签: php simpletest


【解决方案1】:

我只能假设您有多个 SimpleTest autorun.php 脚本的副本。

在您的测试用例文件中执行require 会尝试包含第二个autorun.php 文件(与您的测试套件中包含的文件不同),该文件第二次定义了simpletest_autorun()

行号不匹配的事实增加了我的假设的可信度。

查看错误消息中的完整路径应该会告诉您发生了什么。

确定要保留的副本并删除另一个副本,更新代码或配置中的任何不正确路径,包括 php.ini 中的 include_path

【讨论】:

    猜你喜欢
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-22
    • 2023-03-29
    • 1970-01-01
    • 2016-02-24
    相关资源
    最近更新 更多