考虑具有以下代码的名为user的控制器
class User_Controller extends TinyMVC_Controller
{
function index()
{
$oUserEntity = new User_Entity_Model();
$oUserEntity->guid = 1;
$oUserEntity->name = 'aaaaaa';
$oUserEntity->username = 'aaaaaaa';
$oUserEntity->password = 'newnew';
$oUserEntity->email = 'aaaaaa@gmail.com';
$oUserEntity->language = 'en';
$oUserEntity->code = 'xyz';
$oUserEntity->save();
}
}
?>以及相应的模型user_entity_model.php,
<?php
class User_Entity_Model extends Entity_Model
{
/* some code..*/
public function save() {
// Save generic stuff
if (!parent::save()) {
return false;
}
// Now save specific stuff
return $this->create_user_entity($this->get('guid'), $this->get('name'), $this->get('username'),
$this->get('password'), $this->get('email'), $this->get('language'), $this->get('code'));
}
public function create_user_entity($guid, $name, $username, $password,$email, $language, $code) {
global $CONFIG;
$guid = (int)$guid;
$query = "INSERT into users_entity
(guid, name, username, password, sapcode, salt, email, language, code) values ($guid, '$name', '$username', '$password', '$email', '$language', '$code')";
$result = $this->db->query($query);
return $guid;
}
}我用最简单的方法来测试代码。因此,为了测试函数save(),我创建了test文件夹和测试文件userEntityTest.php
class userEntityTest extends UnitTestCase
{
function testSave(){
$oUserEntity = new User_Entity_Model();
$oUserEntity->guid = 1;
$oUserEntity->name = 'aaaa';
$oUserEntity->username = 'aaaa';
$oUserEntity->password = 'newnew';
$oUserEntity->email = 'cool123@gmail.com';
$oUserEntity->language = 'en';
$oUserEntity->code = 'xyz';
$guid = $oUserEntity->save();
$cp = new UnitTestCase();
$cp->AssertNotEqual($guid, 0);
}}
在浏览器中执行测试时,我得到了以下错误
(!)致命错误:在第3行的C:\wamp\www\ portal\tinymvc\myapp\models\user_entity_model.php中找不到类'Entity_Model‘ userEntityTest.php fails:-> Bad TestSuite userEntityTest.php有错误[userEntityTest.php中没有可运行的测试用例] 0/0测试用例完成:0通过,1失败,0异常。
请帮助我成功地运行测试。
发布于 2012-10-22 21:20:23
我认为命名测试模块userEntityTest.php是错误的,因为这个框架可能会出现‘_model’后缀。请参见带有备注的黄色框( http://www.tinymvc.com/documentation/index.php/Documentation:Models#ynote ),而且,您的问题(我认为,在测试类中限制了可见性范围,因为它没有user_entity_model的父类(即entity_model) )无法创建用户实体模型的新实例)可能无法解决,因为您的模型类似乎不是从TinyMVC_Model派生的,这意味着使您的父类广泛可用。实际上,我没有看到您调用测试的位置,但是如果您试图模拟模型的行为,那么在所有适当的规则方面,让您的类从TinyMVC_Model派生出来。
https://stackoverflow.com/questions/12858412
复制相似问题