Commit 55dce6b5 authored by Romain Neutron's avatar Romain Neutron Committed by Fabien Potencier

Test session service provider with routes that does not use session

parent c2dff3ca
...@@ -103,7 +103,8 @@ class SessionServiceProvider implements ServiceProviderInterface ...@@ -103,7 +103,8 @@ class SessionServiceProvider implements ServiceProviderInterface
return; return;
} }
if ($session = $event->getRequest()->getSession()) { $session = $event->getRequest()->getSession();
if ($session && $session->isStarted()) {
$session->save(); $session->save();
$params = session_get_cookie_params(); $params = session_get_cookie_params();
......
...@@ -14,8 +14,7 @@ namespace Silex\Tests\Provider; ...@@ -14,8 +14,7 @@ namespace Silex\Tests\Provider;
use Silex\Application; use Silex\Application;
use Silex\WebTestCase; use Silex\WebTestCase;
use Silex\Provider\SessionServiceProvider; use Silex\Provider\SessionServiceProvider;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpFoundation\Request;
/** /**
* SessionProvider test cases. * SessionProvider test cases.
...@@ -77,4 +76,32 @@ class SessionServiceProviderTest extends WebTestCase ...@@ -77,4 +76,32 @@ class SessionServiceProviderTest extends WebTestCase
return $app; return $app;
} }
public function testWithRoutesThatDoesNotUseSession()
{
$app = new Application();
$app->register(new SessionServiceProvider(), array(
'session.test' => true,
));
$app->get('/', function () {
return 'A welcome page.';
});
$app->get('/robots.txt', function () {
return 'Informations for robots.';
});
$app['debug'] = true;
$app['exception_handler']->disable();
$client = new Client($app);
$client->request('get', '/');
$this->assertEquals('A welcome page.', $client->getResponse()->getContent());
$client->request('get', '/robots.txt');
$this->assertEquals('Informations for robots.', $client->getResponse()->getContent());
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment