Selenium RC - 无法重新声明 PHPUnit_Framework_TestCase 类

发布于 2024-10-11 08:22:57 字数 1283 浏览 5 评论 0原文

我在网上很多地方都找到了这个问题,但没有实际的解决方案。运行测试的默认代码是

<?php

set_include_path(get_include_path() . PATH_SEPARATOR . './PEAR/');
require_once 'Testing/Selenium.php';
require_once 'PHPUnit/Framework/TestCase.php';

class GoogleTest extends PHPUnit_Framework_TestCase
{
    private $selenium;

    public function setUp()
    {
        $this->selenium = new Testing_Selenium("*firefox", 
                                               "http://www.google.com");
        $this->selenium->start();
    }

    public function tearDown()
    {
        $this->selenium->stop();
    }

    public function testGoogle()
    {
        $this->selenium->open("/");
        $this->selenium->type("q", "hello world");
        $this->selenium->click("btnG");
        $this->selenium->waitForPageToLoad(10000);
        $this->assertRegExp("/Google Search/", $this->selenium->getTitle());
    }

}
?>

这给了我以下错误

Fatal error: Cannot redeclare class PHPUnit_Framework_TestCase in /usr/lib/php/PHPUnit/Framework/TestCase.php on line 115

我的包含路径看起来像这样

.:/usr/lib/php/ZendLatest/library/:/usr/lib/php/:./PEAR/

任何人都可以帮我解决这个问题吗?重新声明该类的位置并不明显,是在上述文件的第 115 行还是其他地方?

谢谢

This I have found on the net in various places but with no actual solution. The default code for running a test is

<?php

set_include_path(get_include_path() . PATH_SEPARATOR . './PEAR/');
require_once 'Testing/Selenium.php';
require_once 'PHPUnit/Framework/TestCase.php';

class GoogleTest extends PHPUnit_Framework_TestCase
{
    private $selenium;

    public function setUp()
    {
        $this->selenium = new Testing_Selenium("*firefox", 
                                               "http://www.google.com");
        $this->selenium->start();
    }

    public function tearDown()
    {
        $this->selenium->stop();
    }

    public function testGoogle()
    {
        $this->selenium->open("/");
        $this->selenium->type("q", "hello world");
        $this->selenium->click("btnG");
        $this->selenium->waitForPageToLoad(10000);
        $this->assertRegExp("/Google Search/", $this->selenium->getTitle());
    }

}
?>

This gives me the following error

Fatal error: Cannot redeclare class PHPUnit_Framework_TestCase in /usr/lib/php/PHPUnit/Framework/TestCase.php on line 115

My include path looks like this

.:/usr/lib/php/ZendLatest/library/:/usr/lib/php/:./PEAR/

Can anyone help me fix this? It isn't obvious where the class is being re-declared, is it on line 115 of the file mentioned above or somewhere else?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终弃我 2024-10-18 08:22:57

我通过将行更改

 require_once 'PHPUnit/Framework/TestCase.php';

require_once 'PHPUnit/Framework.php';

The Framework.php file is the Bootstrap for PHPUnit 并包含此处理所有其他包含内容来解决此问题。包含 TestCase.php 不起作用,因为它不是 Bootstrap 文件,因此无法正确加载 PHPUnit。

I have solved this by changing the line

 require_once 'PHPUnit/Framework/TestCase.php';

To

require_once 'PHPUnit/Framework.php';

The Framework.php file is the Bootstrap for PHPUnit and including this deals with all other includes. Including TestCase.php doesn't work because that isn't the Bootstrap file and thus doesn't load PHPUnit correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文