Framework: LogicException: Session name cannot be empty

Created on 17 Dec 2017  路  3Comments  路  Source: laravel/framework

  • Laravel Version: 5.4.36
  • PHP Version: 7.1.8

Description:

When running phpunit with --process-isolation flag I get this error:
LogicException: Session name cannot be empty, did you forget to call "parent::open()" in "Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler"?

When running without process isolation, the test passes.

Steps To Reproduce:

After exploring where it fails, I found that the error is thrown when attempt() method is called:

if (auth()->attempt($this->credentials($request), $request->remember)) {
    if ($request->isJson()) {
        return response()->json([
            'user' => auth()->user(),
            'message' => __('You have been successfully logged in!'),
        ], 201);
    }

    return redirect()->intended(route($this->redirectTo));
}

Most helpful comment

For anyone else struggling with this add the following to a service providers register method:

~~~ php
$this->app->extend('session.store', function (Store $store, Container $container) {
$handler = $store->getHandler();
$config = $container->make('config');
if ($handler instanceof NullSessionHandler) {
$handler->open(null, $config->get('auth.defaults.guard'));
}

        return $store;
});

~~~

All 3 comments

5.4 is no longer supported. Kindly try this on a 5.5 install and let us know if the issue still persists.

Ok, upgraded to laravel 5.5.25 and phpunit 6.5.5 and the test passes.
Also I don't need to run --process-isolation because it uses so much less memory now. Almost 4 times less.

For anyone else struggling with this add the following to a service providers register method:

~~~ php
$this->app->extend('session.store', function (Store $store, Container $container) {
$handler = $store->getHandler();
$config = $container->make('config');
if ($handler instanceof NullSessionHandler) {
$handler->open(null, $config->get('auth.defaults.guard'));
}

        return $store;
});

~~~

Was this page helpful?
0 / 5 - 0 ratings