测试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.

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.