1

これは、さまざまな場所でネット上で見つけましたが、実際の解決策はありません。テストを実行するためのデフォルトのコードは

<?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 行目ですか、それとも別の場所ですか?

ありがとう

4

1 に答える 1

1

行を変更することでこれを解決しました

 require_once 'PHPUnit/Framework/TestCase.php';

require_once 'PHPUnit/Framework.php';

このFramework.phpファイルは PHPUnit の Bootstrap であり、これをインクルードすると、他のすべてのインクルードが処理されます。これはBootstrapTestCase.phpファイルではなく、PHPUnit を正しくロードしないため、インクルードは機能しません。

于 2011-01-13T10:45:48.873 に答える