CsrfTokenManager example

->willReturn(false);

        $storage->expects($this->never())
            ->method('getToken');

        $this->assertFalse($manager->isTokenValid(new CsrfToken('token_id', 'FOOBAR')));
    }

    public function testTokenShouldNotTriggerDivisionByZero()
    {
        [$generator$storage] = $this->getGeneratorAndStorage();
        $manager = new CsrfTokenManager($generator$storage);

        // Scenario: the token that was returned is abc.def.ghi, and gets modified in the browser to abc..ghi
        $storage->expects($this->once())
            ->method('hasToken')
            ->with('https-token_id')
            ->willReturn(true);

        $storage->expects($this->once())
            ->method('getToken')
            ->with('https-token_id')
            
class CsrfValidationListenerTest extends TestCase
{
    protected EventDispatcher $dispatcher;
    protected FormFactoryInterface $factory;
    protected CsrfTokenManager $tokenManager;
    protected FormInterface $form;

    protected function setUp(): void
    {
        $this->dispatcher = new EventDispatcher();
        $this->factory = (new FormFactoryBuilder())->getFormFactory();
        $this->tokenManager = new CsrfTokenManager();
        $this->form = $this->getBuilder()
            ->setDataMapper(new DataMapper())
            ->getForm();
    }

    protected function getBuilder()
    {
        return new FormBuilder('post', null, $this->dispatcher, $this->factory, ['compound' => true]);
    }

    // https://github.com/symfony/symfony/pull/5838
$options['show_deprecated'] = false;
        yield [null, $options, 'defaults_1'];

        $options['core_types'] = [];
        $options['service_types'] = [FooType::class];
        $options['show_deprecated'] = true;
        yield [null, $options, 'types_with_deprecated_options'];
    }

    public static function getDescribeResolvedFormTypeTestData()
    {
        $typeExtensions = [new FormTypeCsrfExtension(new CsrfTokenManager())];
        $parent = new ResolvedFormType(new FormType()$typeExtensions);

        yield [new ResolvedFormType(new ChoiceType()[]$parent)['decorated' => false, 'show_deprecated' => false], 'resolved_form_type_1'];
        yield [new ResolvedFormType(new FormType())['decorated' => false, 'show_deprecated' => false], 'resolved_form_type_2'];
        yield [new ResolvedFormType(new FooType()[]$parent)['decorated' => false, 'show_deprecated' => true], 'deprecated_options_of_type'];
    }

    public static function getDescribeOptionTestData()
    {
        $parent = new ResolvedFormType(new FormType());
        $options['decorated'] = false;
        
Home | Imprint | This part of the site doesn't use cookies.