doupo5178 2012-10-12 11:48
浏览 24

测试tinymvc

Consider a controller named user with the following code

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();

  }
}

?>

and its corresponding model named 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;

}

}

I used simpletest for testing the code. So,to test the function save(), i created tests folder and the test file 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);
}

}

I got the following error when i executed the test in browser

( ! ) Fatal error: Class 'Entity_Model' not found in C:\wamp\www\career portal\tinymvc\myapp\models\user_entity_model.php on line 3

userEntityTest.php Fail: -> Bad TestSuite [userEntityTest.php] with error [No runnable test cases in [userEntityTest.php]] 0/0 test cases complete: 0 passes, 1 fails and 0 exceptions.

Please help me to successfully run the tests.

  • 写回答

1条回答 默认 最新

  • douzhi1919 2012-10-22 21:20
    关注

    I think naming test module userEntityTest.php is wrong, because ‘_model’ suffix is likely to be present by this framework. See the yellow box with note here http://www.tinymvc.com/documentation/index.php/Documentation:Models#ynote Moreover, your problem (which is, I suppose, restricted visibility scope in test class which cannot create a new instance of the user entity model because of it has not parent class for user_entity_model (i.e. entity_model) available) may not be solved since your model classes do not seem to be derived from TinyMVC_Model, that means making your parent classes widely available is all upon you. Actually I do not see the place where you calling your test, but if you’re trying to simulate model’s behavior, make your class a derivative from TinyMVC_Model with respect to all due rules.

    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加