getClientAuthenticatedAsAdmin(); } if (!$this instanceof WebTestCase) { throw new \LogicException(sprintf('The current class does not implements %s', WebTestCase::class)); } $client = static::createClient(); $userRepository = static::getContainer()->get(UserRepository::class); $user = $userRepository->findOneByUsernameOrEmail($username); if (null === $user) { throw new \RuntimeException(sprintf('user with username or email %s not found', $username)); } $client->loginUser($user); return $client; } public function getClientAuthenticatedAsAdmin(): KernelBrowser { if (!$this instanceof WebTestCase) { throw new \LogicException(sprintf('The current class does not implements %s', WebTestCase::class)); } $client = static::createClient(); /** @var \Symfony\Component\Security\Core\User\InMemoryUserProvider $userProvider */ $userProvider = static::getContainer()->get('security.user.provider.concrete.in_memory'); $user = $userProvider->loadUserByIdentifier('admin'); $client->loginUser($user); return $client; } }