简体   繁体   中英

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

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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