0
votes

I am testing with PHPUnit 4.0, Laravel 5.2, PHP 5.5.9, and keep getting the error ERROR: exception 'RuntimeException' with message 'Session store not set on request.' in /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Request.php:85

To rule it out, middleware is enabled.

If I remove {{ old('username') }} from the form, the error goes away. I have seen several posts in regards to this issue using the old() method; however, I have updated the kernel.php, moved the route under a middleware group to reference 'web', even moved start session to the default middleware array() in kernel.php. I have also, tried calling the session from TestCase.php. None of the forums seem to have a working solution. Is there something I'm missing in the syntax, or is there a bug in Laravel?

My kernel.php file looks like

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{

    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class
    ];

    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
        ],
        'api' => [
            'throttle:60,1',
        ],
    ];

    protected $routeMiddleware = [
        'sso'           => \App\Http\Middleware\SsoEnabled::class
        ];
}

My signup.blade.php looks like:

@extends('layouts.main')
@section('body')
    <body>
    <h2>Signup</h2>
    <form class="m-t" role="form" method="POST" action="/signup">
        <div class="form-group">
            <input name="username" type="text" placeholder="Username" value="{{ old('username') }}" required="">
        </div>
        <button type="submit" name="Signup" >Signup</button>
    </form>
    </body>
@endsection

My routes.php looks like:

<?php

    Route::group(['middleware' => ['web']], function () {

            Route::group(array('middleware' => ['sso:0']), function ($key) {

                Route::get('signup/{token}', [
                    'as'   => 'customer.signup',
                    'uses' => 'SignupController@getApplication'
        ]);
    });
});

I have even tried adding a new block to the testCase.php setUp without any luck:

$this->app['config']->set('session', [
    'driver'          => 'array',
    'lifetime'        => 120,
    'expire_on_close' => false,
    'encrypt'         => false,
    'lottery'         => [2, 100],
    'path'            => '/',
    'domain'          => 'localhost',
    'secure'          => true,
    'email'           => 'email@email.com',
    'store'           => 'storage'
]);
    $kernel = app('Illuminate\Contracts\Http\Kernel');
    $kernel->pushMiddleware('Illuminate\Session\Middleware\StartSession');
1
I am having the same isue :'(Rolly

1 Answers

1
votes

Not sure it's the best solution, but I managed to get it working properly by setting session store in setUp().

\Illuminate\Support\Facades\Request::setSession($this->app['session.store'])