|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Security\Http\Tests\EventListener; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Component\HttpFoundation\Request; |
| 16 | +use Symfony\Component\HttpFoundation\Session\Session; |
| 17 | +use Symfony\Component\Security\Http\Event\LogoutEvent; |
| 18 | +use Symfony\Component\Security\Http\EventListener\SessionLogoutListener; |
| 19 | + |
| 20 | +class SessionLogoutListenerTest extends TestCase |
| 21 | +{ |
| 22 | + public function testOnLogoutIfHasNoSession() |
| 23 | + { |
| 24 | + $request = $this->createMock(Request::class); |
| 25 | + $request->method('hasSession')->willReturn(false); |
| 26 | + $request->expects($this->never())->method('getSession'); |
| 27 | + |
| 28 | + $sessionLogoutListener = new SessionLogoutListener(); |
| 29 | + $sessionLogoutListener->onLogout(new LogoutEvent($request, null)); |
| 30 | + } |
| 31 | + |
| 32 | + public function testOnLogoutIfHasSession() |
| 33 | + { |
| 34 | + $session = $this->createMock(Session::class); |
| 35 | + $session->expects($this->once())->method('invalidate'); |
| 36 | + |
| 37 | + $request = $this->createMock(Request::class); |
| 38 | + $request->method('getSession')->willReturn($session); |
| 39 | + $request->method('hasSession')->willReturn(true); |
| 40 | + |
| 41 | + $sessionLogoutListener = new SessionLogoutListener(); |
| 42 | + $sessionLogoutListener->onLogout(new LogoutEvent($request, null)); |
| 43 | + } |
| 44 | +} |
0 commit comments