Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 89ed756

Browse files
dmaichernicolas-grekas
authored andcommitted
failing test to reproduce session problem
1 parent 26fc4e6 commit 89ed756

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SessionController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ public function welcomeAction(Request $request, $name = null)
4343
return new Response(sprintf('Welcome back %s, nice to meet you.', $name));
4444
}
4545

46+
public function cacheableAction()
47+
{
48+
$response = new Response('all good');
49+
$response->setSharedMaxAge(100);
50+
51+
return $response;
52+
}
53+
4654
public function logoutAction(Request $request)
4755
{
4856
$request->getSession()->invalidate();

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ session_welcome:
22
path: /session
33
defaults: { _controller: TestBundle:Session:welcome }
44

5+
session_cacheable:
6+
path: /cacheable
7+
defaults: { _controller: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SessionController::cacheableAction }
8+
59
session_welcome_name:
610
path: /session/{name}
711
defaults: { _controller: TestBundle:Session:welcome }

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ public function testTwoClients($config, $insulate)
126126
$this->assertContains('Welcome back client2, nice to meet you.', $crawler2->text());
127127
}
128128

129+
/**
130+
* @dataProvider getConfigs
131+
*/
132+
public function testCorrectCacheControlHeadersForCacheableAction($config, $insulate)
133+
{
134+
$client = $this->createClient(array('test_case' => 'Session', 'root_config' => $config));
135+
if ($insulate) {
136+
$client->insulate();
137+
}
138+
139+
$client->request('GET', '/cacheable');
140+
141+
$response = $client->getResponse();
142+
$this->assertSame('public, s-maxage=100', $response->headers->get('cache-control'));
143+
}
144+
129145
public function getConfigs()
130146
{
131147
return array(

src/Symfony/Component/HttpFoundation/Session/Session.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public function __construct(SessionStorageInterface $storage = null, AttributeBa
5454
*/
5555
public function start()
5656
{
57-
++$this->usageIndex;
58-
5957
return $this->storage->start();
6058
}
6159

src/Symfony/Component/HttpFoundation/Session/SessionBagProxy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public function getBag()
4444
*/
4545
public function isEmpty()
4646
{
47+
if (!isset($this->data[$this->bag->getStorageKey()])) {
48+
return true;
49+
}
50+
++$this->usageIndex;
51+
4752
return empty($this->data[$this->bag->getStorageKey()]);
4853
}
4954

0 commit comments

Comments
 (0)