client = static::createClient(); $this->em = null; } protected function em(): EntityManagerInterface { if ($this->em === null) { $this->em = static::getContainer()->get(EntityManagerInterface::class); } return $this->em; } protected function createUser(string $email, string $password = 'password'): User { $hasher = static::getContainer()->get(UserPasswordHasherInterface::class); $user = new User(); $user->setEmail($email); $user->setPassword($hasher->hashPassword($user, $password)); $this->em()->persist($user); $this->em()->flush(); return $user; } protected function loginAs(User $user): KernelBrowser { $this->client->loginUser($user); return $this->client; } }