如何在fuelphp中为控制器编写phptest

时间:2015-07-27 08:04:53

标签: php phpunit 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".

出了什么问题

1 个答案:

答案 0 :(得分:0)

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);
    }
}