-
-
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 3e040ef
Showing
2 changed files
with
49 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
46 changes: 46 additions & 0 deletions
46
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,46 @@ | ||
<?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 testOnLogoutIfHasNotSession() | ||
{ | ||
$session = $this->createMock(Session::class); | ||
$session->expects($this->never())->method('invalidate'); | ||
|
||
$request = $this->createMock(Request::class); | ||
$request->expects($this->once())->method('hasSession')->willReturn(false); | ||
|
||
$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->expects($this->once())->method('getSession')->willReturn($session); | ||
$request->expects($this->once())->method('hasSession')->willReturn(true); | ||
|
||
$sessionLogoutListener = new SessionLogoutListener(); | ||
$sessionLogoutListener->onLogout(new LogoutEvent($request, null)); | ||
} | ||
} |