createMock(SessionInterface::class); $extension = new Csrf($session); $functions = $extension->getFunctions(); $this->assertExtensionExists('csrf', [$extension, 'getCsrfField'], $functions, ['is_safe' => ['html']]); $this->assertExtensionExists('csrf_token', [$extension, 'getCsrfToken'], $functions); } /** * @covers \Engelsystem\Renderer\Twig\Extensions\Csrf::getCsrfField */ public function testGetCsrfField(): void { /** @var Csrf|MockObject $extension */ $extension = $this->getMockBuilder(Csrf::class) ->disableOriginalConstructor() ->onlyMethods(['getCsrfToken']) ->getMock(); $extension->expects($this->once()) ->method('getCsrfToken') ->willReturn('SomeRandomCsrfToken'); $this->assertEquals( '', $extension->getCsrfField() ); } /** * @covers \Engelsystem\Renderer\Twig\Extensions\Csrf::__construct * @covers \Engelsystem\Renderer\Twig\Extensions\Csrf::getCsrfToken */ public function testGetCsrfToken(): void { /** @var SessionInterface|MockObject $session */ $session = $this->createMock(SessionInterface::class); $session->expects($this->once()) ->method('get') ->with('_token') ->willReturn('SomeOtherCsrfToken'); $extension = new Csrf($session); $this->assertEquals('SomeOtherCsrfToken', $extension->getCsrfToken()); } }