|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
|
| 16 | +use Symfony\Component\HttpFoundation\Cookie; |
16 | 17 | use Symfony\Component\HttpFoundation\Response;
|
17 | 18 | use Symfony\Component\HttpFoundation\Request;
|
| 19 | +use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
18 | 20 | use Symfony\Component\HttpKernel\HttpKernelInterface;
|
19 | 21 | use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
20 | 22 | use Symfony\Component\HttpKernel\EventListener\SessionListener;
|
@@ -86,6 +88,22 @@ public function testEmptySessionDoesNotSendCookie()
|
86 | 88 | $this->assertSame(array(), $response->headers->getCookies());
|
87 | 89 | }
|
88 | 90 |
|
| 91 | + public function testEmptySessionWithNewSessionIdDoesSendCookie() |
| 92 | + { |
| 93 | + $this->sessionHasBeenStarted(); |
| 94 | + $this->sessionIsEmpty(); |
| 95 | + $this->fixSessionId('456'); |
| 96 | + |
| 97 | + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); |
| 98 | + $request = Request::create('/', 'GET', array(), array(new Cookie('MOCKSESSID', '123'))); |
| 99 | + $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); |
| 100 | + $this->listener->onKernelRequest($event); |
| 101 | + |
| 102 | + $response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST); |
| 103 | + |
| 104 | + $this->assertNotEmpty($response->headers->getCookies()); |
| 105 | + } |
| 106 | + |
89 | 107 | public function testUnstartedSessionIsNotSave()
|
90 | 108 | {
|
91 | 109 | $this->sessionHasNotBeenStarted();
|
@@ -150,6 +168,13 @@ private function sessionIsEmpty()
|
150 | 168 | ->will($this->returnValue(true));
|
151 | 169 | }
|
152 | 170 |
|
| 171 | + private function fixSessionId($sessionId) |
| 172 | + { |
| 173 | + $this->session->expects($this->any()) |
| 174 | + ->method('getId') |
| 175 | + ->will($this->returnValue($sessionId)); |
| 176 | + } |
| 177 | + |
153 | 178 | private function getSession()
|
154 | 179 | {
|
155 | 180 | $mock = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')
|
|
0 commit comments