Testing Laravel 4 in controllers

I have a problem with test controllers in Laravel 4.

I have the following code:

public function getRemind()
{
    $status = \Session::get('status');
    $error = \Session::get('error');
    $email = \Session::get('email');

    return \View::make('admin/reminds/remind_form', compact('status', 'error', 'email'));
}

And I want to check if the correct data in the views is correctly transmitted by the controller:

public function testGetRemind()
{
    \Session::set('status', 'status');
    \Session::set('error', 'error');
    \Session::set('email', 'email');
    $response = $this->action('GET', 'Admin\RemindersController@getRemind');
    $this->assertTrue($response->isOk(), 'Get remind action is not ok');
    $this->assertViewHas('status', 'status');
    $this->assertViewHas('error', 'error');
    $this->assertViewHas('email', 'email');
}

But that will not work.

Also, I can not make fun of the session class , because it is not valid with the framework - there are a lot of errors when trying to do this.

+4
source share
1 answer

Call Session::start()at the beginning of your test. When you call the URL in the test, the session starts, if it is not already running, and then deletes all existing data.

v4.1.23 $this->session($arrayOfSessionData), .

+10

All Articles