为什么我会收到此错误?致命错误:类“TestCase”未找到
即使我已经包含了 TestCase 类?
<?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("[email protected]", $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(new TestWidgetSession("testAuthorization"));
$testRunner = new TestRunner();
$testRunner->run($suite);
?>
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("[email protected]", $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(new TestWidgetSession("testAuthorization"));
$testRunner = new TestRunner();
$testRunner->run($suite);
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该文件肯定不会包含
TestCase
的任何定义,但是PHPUnit_Framework_TestCase
。请小心并使用正确的类名。我假设这同样适用于:
这是
PHPUnit_Framework_TestSuite
而不是TestSuite
。您只需要要求/包含自动加载程序,这对于 PHPUnit 的类来说就足够了。
This file will most certainly not contain any definition of
TestCase
butPHPUnit_Framework_TestCase
. Take care and use the right classname.I assume the same applies to:
which is
PHPUnit_Framework_TestSuite
and notTestSuite
.And you only need to require/include the autloader, that's enough for PHPUnit's classes.