简体   繁体   English

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

[英]how to write a phptest for controller in fuelphp

I only have a controller and view, I want to mock a http request to test this controller, I use fuelphp, hope someone can give me some advice or demo 我只有一个控制器和视图,我想模拟一个http请求来测试该控制器,我使用fuelphp,希望有人可以给我一些建议或演示

class Controller_Index extends Controller_Template{
    public function action_index(){
        $view = View::forge('index');
        $this->template->content = $view;
    }
}

I write like this 我这样写

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 oil test result php油测试结果

There was 1 failure:
1) Warning
No tests found in class "Test_Controller_index".

what's wrong 怎么了

All unit tests in fuelphp need to take the form of test_ or they won't be recognised. fuelphp中的所有单元测试都需要采用test_的形式,否则它们将不会被识别。

Try this: (not the different function name) 试试这个:(不是不同的函数名)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM