liip / liip/LiipFunctionalTestBundle

Add values to the session array

Open
#383 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

support
Dominant language
PHP
Stars
648
Forks
179
PR merge metrics
No merged PRs in 30d

Description

I'm having a controller which reads an integer from the session array in this manner:

if ($session->has('administration')) { $id = $session->get('entity_id'); return $this->getDoctrine()->getRepository('AppBundle:SomeEntity')->find($id); }

Currently I'm writing tests for this controller action but I can't find how to inject this integer in the sessions array. I tried the following:

$this->client = $this->makeClient(true); $this->client->getContainer()->set('session.storage.options.entity_id', 12);

I also tried the following:
$this->client = $this->makeClient(true); $session = new Session(new MockFileSessionStorage()); $session->set('administration', 12); $this->client->getContainer()->set('session', $session);

This, however doesn't work and seems to just ignore the value. Therefore, my question is how to store values in the session array in a functional test environment?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the functional test setup using makeClient(true), the client container, and Symfony's Session with MockFileSessionStorage. Determine how a session value can be made available to the controller during the test, then verify that the controller reads entity_id and resolves the entity. Done means the session value is reliably available in the functional test.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, symfony
Domain
backend, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.