![](/img/trans.png)
[英]how to get parameter POST or GET and showing in controller with FuelPHP framework
[英]how to write a phptest for controller in fuelphp
我只有一個控制器和視圖,我想模擬一個http請求來測試該控制器,我使用fuelphp,希望有人可以給我一些建議或演示
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".
怎么了
fuelphp中的所有單元測試都需要采用test_的形式,否則它們將不會被識別。
試試這個:(不是不同的函數名)
class Test_Controller_index extends TestCase{
public function test_controller(){
$expected = View::forge('index');
$response = Request::forge('index')
->set_method('GET')
->execute()
->response();
$assertValue = $response->body->content;
$this->assertSame($expected, $assertValue);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.