【发布时间】:2015-07-27 08:04:52
【问题描述】:
我只有一个控制器和视图,我想mock一个http请求来测试这个控制器,我用的是fuelphp,希望有人能给我一些建议或demo
class Controller_Index extends Controller_Template{
public function action_index(){
$view = View::forge('index');
$this->template->content = $view;
}
}
我是这样写的
class Test_Controller_index extends TestCase{
public function TestController(){
$expected = View::forge('index');
$response = Request::forge('index')
->set_method('GET')
->execute()
->response();
$assertValue = $response->body->content;
$this->assertSame($expected, $assertValue);
}
}
php试油结果
There was 1 failure:
1) Warning
No tests found in class "Test_Controller_index".
怎么了
【问题讨论】:
-
麻烦我了,请问可以请教吗?
-
如果您阅读错误消息,您会看到测试框架没有接收任何测试。尝试调用你的测试方法
testController(),看看它是否可以运行。 -
另外我注意到你只是在测试视图加载。这种测试是没有用的,因为您所做的只是断言框架可以加载视图,而框架自己的测试已经涵盖了这一点。
-
感谢您回答我,实际上,我只是想模拟一个 http 请求,因为我的项目已损坏,我没有 db 并且一些 url 跳转未使用,所以我想做这个 mock.er ..现在我不知道这是否正确,
-
您的测试可能无法运行,因为您需要将方法命名为
testController而不是TestController