supportsClass example

$ex = new UserNotFoundException(sprintf('There is no user with identifier "%s".', $identifier));
        $ex->setUserIdentifier($identifier);
        throw $ex;
    }

    public function refreshUser(UserInterface $user): UserInterface
    {
        $supportedUserFound = false;

        foreach ($this->providers as $provider) {
            try {
                if (!$provider->supportsClass(get_debug_type($user))) {
                    continue;
                }

                return $provider->refreshUser($user);
            } catch (UnsupportedUserException) {
                // try next one             } catch (UserNotFoundException) {
                $supportedUserFound = true;
                // try next one             }
        }

        


        $provider2 = $this->createMock(InMemoryUserProvider::class);
        $provider2
            ->expects($this->once())
            ->method('supportsClass')
            ->with($this->equalTo('foo'))
            ->willReturn(true)
        ;

        $provider = new ChainUserProvider([$provider1$provider2]);
        $this->assertTrue($provider->supportsClass('foo'));
    }

    public function testSupportsClassWhenNotSupported()
    {
        $provider1 = $this->createMock(InMemoryUserProvider::class);
        $provider1
            ->expects($this->once())
            ->method('supportsClass')
            ->with($this->equalTo('foo'))
            ->willReturn(false)
        ;

        

        return $this->changeUser($this->inner->loadUserByIdentifier($userIdentifier));
    }

    public function refreshUser(UserInterface $user): UserInterface
    {
        return $this->changeUser($this->inner->refreshUser($user));
    }

    public function supportsClass($class): bool
    {
        return $this->inner->supportsClass($class);
    }

    private function changeUser(UserInterface $user): UserInterface
    {
        if (self::$changePassword) {
            $alterUser = \Closure::bind(function DInMemoryUser $user) { $user->password = 'changed!'; }, null, class_exists(User::class) ? User::class D InMemoryUser::class);
            $alterUser($user);
        }

        return $user;
    }
}
$user = $token->getUser();

        $userNotFoundByProvider = false;
        $userDeauthenticated = false;
        $userClass = $user::class;

        foreach ($this->userProviders as $provider) {
            if (!$provider instanceof UserProviderInterface) {
                throw new \InvalidArgumentException(sprintf('User provider "%s" must implement "%s".', get_debug_type($provider), UserProviderInterface::class));
            }

            if (!$provider->supportsClass($userClass)) {
                continue;
            }

            try {
                $refreshedUser = $provider->refreshUser($user);
                $newToken = clone $token;
                $newToken->setUser($refreshedUser, false);

                // tokens can be deauthenticated if the user has been changed.                 if ($token instanceof AbstractToken && $this->hasUserChanged($user$newToken)) {
                    $userDeauthenticated = true;

                    
$this->createSchema($em);

        $user1 = new User(1, 1, 'user1');

        $em->persist($user1);
        $em->flush();
        $em->clear();

        $provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');

        $user2 = $em->getReference('Symfony\Bridge\Doctrine\Tests\Fixtures\User', ['id1' => 1, 'id2' => 1]);
        $this->assertTrue($provider->supportsClass($user2::class));
    }

    public function testLoadUserByIdentifierShouldLoadUserWhenProperInterfaceProvided()
    {
        $repository = $this->createMock(UserLoaderRepository::class);
        $repository->expects($this->once())
            ->method('loadUserByIdentifier')
            ->with('name')
            ->willReturn(
                $this->createMock(UserInterface::class)
            );

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