【发布时间】:2013-12-23 14:05:00
【问题描述】:
我正在基于 Union of RAD 的框架项目在 Lithium(PHP 框架)中构建一个玩具应用程序。在浏览器中一切正常,但是在运行集成测试时,routes.php 没有加载,因此路由不起作用。
这是我正在测试的代码:
class StaffController extends \lithium\action\Controller {
public function add() {
$staff = Staff::create();
if (($this->request->data) && $staff->save($this->request->data)) {
return $this->redirect(array('Staff::view', 'args' => array($staff->id)));
}
return compact('staff');
}
我的测试:
public function testAdd() {
//Router::connect('/{:controller}/{:action}/{:args}');
$request = new Request();
$request->data = array('name' => 'Brand new user');
$controller = new StaffController(array('request' => $request));
/* @var $response \lithium\action\Response */
$response = $controller->add();
$this->assertEqual(302, $response->status['code']);
}
注意注释掉的行 - Router::connect('/{:controller}/{:action}/{:args}'); - 如果我取消注释,一切都很好。
我感到困惑的是,为什么在单元测试中运行时,app/config/routes.php(我定义路由的地方)没有加载。据我所知,app/config/bootstrap/action.php 向加载 routes.php 的 Dispatcher 的“run”方法添加了一个过滤器。
当然,我可能完全错过了这里的重点!我很感激你能给我的任何指导!
【问题讨论】: