开发者

Why am I getting this error? Fatal error: Class 'TestCase' not found

Even though I have got the TestCase class included?

    <?php

require_once("PHPUnit/Autoload.php");
require_once("PHPUnit/Framework/TestCase.php");
require_once("PHPUnit/Framework/TestSuite.php");

class WidgetSession {
    public function __construct($one, $two){}
    public function login() {}
    public function isLoggedIn() {return null;}
    public function getUser(){
        return new WidgetUser();
    }
}

class WidgetUser{
    public $first_name = "";
    public $last_name = "";
    public $email = "";

    public function isSalesPerson() {return null;}
    public function isSalesManager() {return null;}
}

class TestWidgetSession extends TestCase {

    private $_session;
    function setUp(){
        $dsn = array(
            'phptype' => "pgsql",
            'hostspec' => "localhost",
            'database' => "widgetworld",
            'username' => "wuser",
            'password' => "foobar"
        );
        $this->_session = new WidgetSession($dsn, true);
    }

    function testValidLogin(){
        $this->_session->login("ed", "12345");
        $this->assertEqual(true, $this->_session->isLoggedIn());
    }

    function testInvalidLogin(){
        $this->_session->login("ed", "54321"); //fail
        $this->assertEquals(false, $this->_session->isLoggedIn());
    }

    function testUser(){
        $user = $this->_session->getUser();
        $this->assertEquals("Lecky Thompson", $user->last_name);
        $this->assertEquals("Ed", $user->first_name);
        $this->assertEquals("ed@lecky-thompson.com", $user->email);
    }

    function testAuthorization(){
        $user = $this->_session->getUser();
        $this->assertEquals("Sales Person", $user->role);
        $this->assertEquals(true, $user->isSalesPerson());
        $this->assertEquals(false, $user->isSalesManager());
        $this->assertEquals(false, $user->isAccountant());
    }
}

$suite = new TestSuite;
$suite->addTest(new TestWidgetSession("testValidLogin"));
$suite->addTest(new TestWidgetSession("testInvalidLogin"));
$suite->addTest(new TestWidgetSession("testUser"));
$suite->addTest(ne开发者_JS百科w TestWidgetSession("testAuthorization"));
$testRunner = new TestRunner();
$testRunner->run($suite);
?>


require_once("PHPUnit/Framework/TestCase.php");

This file will most certainly not contain any definition of TestCase but PHPUnit_Framework_TestCase. Take care and use the right classname.

I assume the same applies to:

require_once("PHPUnit/Framework/TestSuite.php");

which is PHPUnit_Framework_TestSuite and not TestSuite.

And you only need to require/include the autloader, that's enough for PHPUnit's classes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜