private function login() { $this->loginUser = new User(); $this->loginUser->setEmail('*****@*****.**')->setName('Test User 2'); $factory = $this->client->getKernel()->getContainer()->get('security.encoder_factory'); $encoder = $factory->getEncoder($this->loginUser); $hashed_password = $encoder->encodePassword('password', $this->loginUser->getSalt()); $this->loginUser->setPassword($hashed_password); $em = $this->getEntityManager(); $em->persist($this->loginUser); $em->flush(); $crawler = $this->userClient->request('GET', '/auth/login'); $form = $crawler->selectButton('Log in')->form(); $form->setValues(array('email' => $this->loginUser->getEmail(), 'password' => 'password')); $this->userClient->submit($form); }