-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Check if it has session before getSession()
- Loading branch information
1 parent
88c5349
commit 17d54fd
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/Symfony/Component/Security/Http/Tests/EventListener/SessionLogoutListenerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Security\Http\Tests\EventListener; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Session\Session; | ||
use Symfony\Component\Security\Http\Event\LogoutEvent; | ||
use Symfony\Component\Security\Http\EventListener\SessionLogoutListener; | ||
|
||
class SessionLogoutListenerTest extends TestCase | ||
{ | ||
public function testOnLogoutIfHasNoSession() | ||
{ | ||
$request = $this->createMock(Request::class); | ||
$request->method('hasSession')->willReturn(false); | ||
$request->expects($this->never())->method('getSession'); | ||
|
||
$sessionLogoutListener = new SessionLogoutListener(); | ||
$sessionLogoutListener->onLogout(new LogoutEvent($request, null)); | ||
} | ||
|
||
public function testOnLogoutIfHasSession() | ||
{ | ||
$session = $this->createMock(Session::class); | ||
$session->expects($this->once())->method('invalidate'); | ||
|
||
$request = $this->createMock(Request::class); | ||
$request->method('getSession')->willReturn($session); | ||
$request->method('hasSession')->willReturn(true); | ||
|
||
$sessionLogoutListener = new SessionLogoutListener(); | ||
$sessionLogoutListener->onLogout(new LogoutEvent($request, null)); | ||
} | ||
} |