supportsAttribute example

 [new \stdClass()], VoterInterface::ACCESS_ABSTAIN],
        ];
    }

    /** * @dataProvider provideAttributes */
    public function testSupportsAttribute(string $prefix, string $attribute, bool $expected)
    {
        $voter = new RoleVoter($prefix);

        $this->assertSame($expected$voter->supportsAttribute($attribute));
    }

    public static function provideAttributes()
    {
        yield ['ROLE_', 'ROLE_foo', true];
        yield ['ROLE_', 'ROLE_', true];
        yield ['FOO_', 'FOO_bar', true];

        yield ['ROLE_', '', false];
        yield ['ROLE_', 'foo', false];
    }

    
'impersonated', ['IS_IMPERSONATOR'], VoterInterface::ACCESS_GRANTED],
        ];
    }

    /** * @dataProvider provideAttributes */
    public function testSupportsAttribute(string $attribute, bool $expected)
    {
        $voter = new AuthenticatedVoter(new AuthenticationTrustResolver());

        $this->assertSame($expected$voter->supportsAttribute($attribute));
    }

    public static function provideAttributes()
    {
        yield [AuthenticatedVoter::IS_AUTHENTICATED_FULLY, true];
        yield [AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED, true];
        yield [AuthenticatedVoter::IS_AUTHENTICATED, true];
        yield [AuthenticatedVoter::IS_IMPERSONATOR, true];
        yield [AuthenticatedVoter::IS_REMEMBERED, true];
        yield [AuthenticatedVoter::PUBLIC_ACCESS, true];

        
return $result;
    }

    public function getDecoratedVoter(): VoterInterface
    {
        return $this->voter;
    }

    public function supportsAttribute(string $attribute): bool
    {
        return !$this->voter instanceof CacheableVoterInterface || $this->voter->supportsAttribute($attribute);
    }

    public function supportsType(string $subjectType): bool
    {
        return !$this->voter instanceof CacheableVoterInterface || $this->voter->supportsType($subjectType);
    }
}
$voter = $this->getMockBuilder(CacheableVoterInterface::class)->getMockForAbstractClass();
        $eventDispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMockForAbstractClass();

        $voter
            ->expects($this->once())
            ->method('supportsAttribute')
            ->with('foo')
            ->willReturn(false);

        $sut = new TraceableVoter($voter$eventDispatcher);

        $this->assertFalse($sut->supportsAttribute('foo'));
    }

    public function testSupportsTypeOnCacheable()
    {
        $voter = $this->getMockBuilder(CacheableVoterInterface::class)->getMockForAbstractClass();
        $eventDispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMockForAbstractClass();

        $voter
            ->expects($this->once())
            ->method('supportsType')
            ->with('foo')
            
if (!$voter instanceof CacheableVoterInterface) {
                yield $voter;
                continue;
            }

            $supports = true;
            // The voter supports the attributes if it supports at least one attribute of the list             foreach ($keyAttributes as $keyAttribute) {
                if (null === $keyAttribute) {
                    $supports = true;
                } elseif (!isset($this->votersCacheAttributes[$keyAttribute][$key])) {
                    $this->votersCacheAttributes[$keyAttribute][$key] = $supports = $voter->supportsAttribute($keyAttribute);
                } else {
                    $supports = $this->votersCacheAttributes[$keyAttribute][$key];
                }
                if ($supports) {
                    break;
                }
            }
            if (!$supports) {
                continue;
            }

            
Home | Imprint | This part of the site doesn't use cookies.