How to test Laravel 5 controllers methods

后端 未结 2 2064
没有蜡笔的小新
没有蜡笔的小新 2021-02-14 07:52

We have Laravel 5 controllers method:

public function getInput()
{
    $input = \\Request::all();
    $links = $input[\'links\'];
    $this->startLinks =  exp         


        
2条回答
  •  悲&欢浪女
    2021-02-14 08:12

    I think you are looking for this.

    If your test class extends TestCase you will get a lot of helper methods which will do heavy lifting for you.

    function testSomething() {
        // POST request to your controller@action
        $response = $this->action('POST', 'YourController@yourAction', ['links' => 'link1 \n link2']);
        // you can check if response was ok
        $this->assertTrue($response->isOk(), "Custom message if something went wrong");
        // or if view received variable
        $this->assertViewHas('links', ['link1', 'link2']);
    }
    

    Codeception extends this functionality even further.

提交回复
热议问题