-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There is currently no session available. #41654
Comments
You should not store state in your service and should not call Instead, call it when you need the session
|
Thanks you solve my problem ;-) |
Work's fine but Functionnal test failed with same message "There is currently no session available." Before my functionnal test i call service (who use requestStack) to force/simulate saving context with static::getContainer()->get(myservice) my test/framework.yaml
i must change logic ? |
You need to set a session in you request when unint testing your service, or running you test in a request/response context. maybe similar to #41590 |
ok i explain the application logic. After authenticated, user must select a workspace (the listener check if specific session exist, and redirect to select form is not, after select, session is created and user redirect to homepage). Work's fine. When create functionnal test , i authenticate user with $workspaceSelectedRepository = static::getContainer()->get(WorkspaceSelectedRepository::class);
$workspaceSelectedRepository->save($workspace) declare(strict_types=1);
namespace App\Account\Infrastructure\Persistence;
use App\Account\Domain\Interfaces\WorkspaceSelectedRepositoryInterface;
use App\Account\Domain\WorkspaceSelected;
use Symfony\Component\HttpFoundation\RequestStack;
class WorkspaceSelectedRepository implements WorkspaceSelectedRepositoryInterface
{
/**
* @var RequestStack
*/
private $requestStack;
public const WORKSPACE_SELECTED = 'ssWorkspaceSelected';
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function getSession()
{
return $this->requestStack->getSession();
}
public function has(): bool
{
return $this->getSession()->has(self::WORKSPACE_SELECTED);
}
public function save(WorkspaceSelected $workspaceSelected): void
{
$this->getSession()->set(self::WORKSPACE_SELECTED, $workspaceSelected);
}
public function get(): ?WorkspaceSelected
{
return $this->getSession()->get(self::WORKSPACE_SELECTED);
}
public function delete(): void
{
$this->getSession()->remove(self::WORKSPACE_SELECTED);
}
} I try like $session = static::getContainer()->get('test.service_container')->get('session.factory')->createSession();
$session->set(WorkspaceSelectedRepository ::WORKSPACE_SELECTED, $workpace);
$session->save(); When try that i don't have What's wrong ? i must had session to the client after ? |
i try with symfony/framework-bundle 5.3.x-dev |
Instead of create session before request, i try with your recommandations to set with client request/response context and works fine . $crawler = $this->client->request('GET', self::HOST.'workspace-select');
$validateButton = $crawler->selectButton('Valider');
$form = $validateButton->form([], 'POST');
$form['account_workspace[workspace]']->disableValidation()->select($idworkspace);
$this->client->submit($form); Thanks @jderusse |
I migrate symfony 5.2.x to symfony 5.3.1
I want to fix deprecated message :
I change on my service
to
my service is a listener call on kernel.event_listener
tags: - { name: kernel.event_listener, priority: -10 }
the result is a
I read similary issue #40778 but can't understand how to resolve that on my listener.
Problem's is the listener ? priority ?
I callback to SessionInterface temporarily
@jderusse do you have idea ?
The text was updated successfully, but these errors were encountered: