Skip to content

Commit

Permalink
Add troubleshooting approach to solve Session not set on request.
Browse files Browse the repository at this point in the history
Closes #102.

Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Dec 10, 2015
1 parent 3628b20 commit b92eea8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,12 @@ This error would only occur if your test suite require actual usage of the encry

</phpunit>
```
### Session not set on request

The error might pop-up when testing routes with `Request::old()` or `old()` helper inside the requested view. This is due to Testbench not loading the default global middleware made available with Laravel.

To avoid breaking Backward Compatibility (BC) under 3.1 please add the following code under your `setUp` or `getEnvironmentSetUp` method.

```php
$app->make('Illuminate\Contracts\Http\Kernel')->pushMiddleware('Illuminate\Session\Middleware\StartSession');
```

2 comments on commit b92eea8

@kagan94
Copy link

@kagan94 kagan94 commented on b92eea8 Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an error that "pushMiddleware" doesn't exist.

However, another way to solve this issue (e.g. for unit testing) is to use an array as session driver in the setUp() method in TestCase:
$this->app['request']->setSession($this->app['session']->driver('array'));

@crynobone
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an error that "pushMiddleware" doesn't exist.

The method does exist on Illuminate\Foundation\Http\Middleware so I not sure what you're talking about.

https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/Http/Kernel.php#L205

And furthermore this is only an issue with Testbench 3.1 which targetted for Laravel 5.1

Please sign in to comment.