如何在测试中加载模型?以及如何加载和测试控制器?
致命错误:未找到模型!
这在控制器中有效:#but在测试中不起作用
<?php
# PATH app\modules\adm\classes\model
namespace Adm\Model;
class Medico extends \Orm\Model
{
protected static $_primary_key = array('id');
protected static $_table_name = 'medico';
}
# PATH app\modules\adm\classes\controller
# WORKS!!!
namespace Adm;
use Adm\Model\Medico; # <- WORKS!!!
class Controller_Medicos extends \Controller_Template
{
public function action_index()
{
$data['medicos'] = Medico::find()->select('id','segundo_nome')->limit(1)->get_one();
print_r($data['medicos']->segundo_nome);
$this->template->content = \View::forge('medicos/index');
}
}
# app\modules\tests\adm\classes\model
# DOES NOT WORK!!
namespace Adm;
use Adm\Model\Medico; # <- Adm\Model\Medico NOT FOUND why ?
class Test_Model_Medico extends \TestCase
{
public function test_autocomplete()
{
$medico = Medico::find(1);
$this->assertEquals(2,2);
}
}
答案 0 :(得分:1)
当您通过URL请求控制器时,路由引擎将自动加载模块。
当您通过油运行测试时,这不会发生,因此您可以在测试类的设置部分手动加载它:
\Module::load('adm');