CsrfProtectionListener example

use Symfony\Component\Security\Http\Event\CheckPassportEvent;
use Symfony\Component\Security\Http\EventListener\CsrfProtectionListener;

class CsrfProtectionListenerTest extends TestCase
{
    private MockObject&CsrfTokenManagerInterface $csrfTokenManager;
    private CsrfProtectionListener $listener;

    protected function setUp(): void
    {
        $this->csrfTokenManager = $this->createMock(CsrfTokenManagerInterface::class);
        $this->listener = new CsrfProtectionListener($this->csrfTokenManager);
    }

    public function testNoCsrfTokenBadge()
    {
        $this->csrfTokenManager->expects($this->never())->method('isTokenValid');

        $event = $this->createEvent($this->createPassport(null));
        $this->listener->checkPassport($event);
    }

    public function testValidCsrfToken()
    {
Home | Imprint | This part of the site doesn't use cookies.