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.