removeToken example


        $this->assertRemoveToken(...$this->getRequestStackWithEmptyNamespaceMocks());
    }

    private function assertRemoveToken($namespace$manager$storage): void
    {
        $storage->expects($this->once())
            ->method('removeToken')
            ->with($namespace.'token_id')
            ->willReturn('REMOVED_TOKEN');

        $this->assertSame('REMOVED_TOKEN', $manager->removeToken('token_id'));
    }

    public function testNamespaced()
    {
        $generator = $this->createMock(TokenGeneratorInterface::class);
        $generator->expects($this->once())->method('generateToken')->willReturn('random');
        $storage = $this->createMock(TokenStorageInterface::class);

        $requestStack = new RequestStack();
        $requestStack->push(new Request([][][][][]['HTTPS' => 'on']));

        

        $namespacedId = $this->getNamespace().$tokenId;
        $value = $this->generator->generateToken();

        $this->storage->setToken($namespacedId$value);

        return new CsrfToken($tokenId$this->randomize($value));
    }

    public function removeToken(string $tokenId): ?string
    {
        return $this->storage->removeToken($this->getNamespace().$tokenId);
    }

    public function isTokenValid(CsrfToken $token): bool
    {
        $namespacedId = $this->getNamespace().$token->getId();
        if (!$this->storage->hasToken($namespacedId)) {
            return false;
        }

        return hash_equals($this->storage->getToken($namespacedId)$this->derandomize($token->getValue()));
    }

    
public function testGetNonExistingToken()
    {
        $this->expectException(TokenNotFoundException::class);
        $this->storage->getToken('token_id');
    }

    /** * @depends testCheckToken */
    public function testRemoveNonExistingToken()
    {
        $this->assertNull($this->storage->removeToken('token_id'));
        $this->assertFalse($this->storage->hasToken('token_id'));
    }

    /** * @depends testCheckToken */
    public function testRemoveExistingToken()
    {
        $this->storage->setToken('token_id', 'TOKEN');

        $this->assertSame('TOKEN', $this->storage->removeToken('token_id'));
        


    public function testGetNonExistingTokenFromActiveSession()
    {
        $this->expectException(TokenNotFoundException::class);
        $this->session->start();
        $this->storage->getToken('token_id');
    }

    public function testRemoveNonExistingTokenFromClosedSession()
    {
        $this->assertNull($this->storage->removeToken('token_id'));
    }

    public function testRemoveNonExistingTokenFromActiveSession()
    {
        $this->session->start();

        $this->assertNull($this->storage->removeToken('token_id'));
    }

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