Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.

Commit

Permalink
bug #1343 Fixed Session Service Provider registry (ragboyjr)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.0.x-dev branch.

Discussion
----------

Fixed Session Service Provider registry

The service provider was registering the wrong parameters
to the session listener instead of the actual session class

This fixes #1342

Signed-off-by: RJ Garcia <rj@bighead.net>

Commits
-------

cecdb85 Fixed Session Service Provider registry
  • Loading branch information
fabpot committed May 4, 2016
2 parents 5f0fc5c + cecdb85 commit ad67898
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Silex/Provider/SessionServiceProvider.php
Expand Up @@ -38,7 +38,7 @@ public function register(Container $app)
$app['session.test'] = false;

$app['session'] = function ($app) {
return new Session($app['session.storage']);
return new Session($app['session.storage'], $app['session.attribute_bag'], $app['session.flash_bag']);
};

$app['session.storage'] = function ($app) {
Expand All @@ -61,7 +61,7 @@ public function register(Container $app)
};

$app['session.listener'] = function ($app) {
return new SessionListener($app, $app['session.attribute_bag'], $app['session.flash_bag']);
return new SessionListener($app);
};

$app['session.storage.test'] = function () {
Expand Down
19 changes: 19 additions & 0 deletions tests/Silex/Tests/Provider/SessionServiceProviderTest.php
Expand Up @@ -15,6 +15,7 @@
use Silex\WebTestCase;
use Silex\Provider\SessionServiceProvider;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpFoundation\Session;

/**
* SessionProvider test cases.
Expand Down Expand Up @@ -104,4 +105,22 @@ public function testWithRoutesThatDoesNotUseSession()
$client->request('get', '/robots.txt');
$this->assertEquals('Informations for robots.', $client->getResponse()->getContent());
}

public function testSessionRegister()
{
$app = new Application();

$attrs = new Session\Attribute\AttributeBag();
$flash = new Session\Flash\FlashBag();
$app->register(new SessionServiceProvider(), array(
'session.attribute_bag' => $attrs,
'session.flash_bag' => $flash,
'session.test' => true,
));

$session = $app['session'];

$this->assertSame($flash, $session->getBag('flashes'));
$this->assertSame($attrs, $session->getBag('attributes'));
}
}

0 comments on commit ad67898

Please sign in to comment.