public function validate($data, Constraint $constraint) { $id = $data->getId(); $username = $data->getUsername(); if ($id === null && $this->userManager->findUserByUsername($username)) { $this->context->addViolationAt('username', $constraint->message, array('%username%' => $username)); } if ($id !== null && ($user = $this->userManager->findUserByUsername($username)) && $user->getId() !== $id) { $this->context->addViolationAt('username', $constraint->message, array('%username%' => $username)); } }
public function testHRLogin() { $this->loadFixtures(array('Polcode\\Bundle\\RecruitmentBundle\\DataFixtures\\ORM\\LoadUserData', 'Polcode\\Bundle\\RecruitmentBundle\\DataFixtures\\ORM\\LoadProjectData')); $hr = $this->userManager->findUserByUsername('hr'); $this->assertNotNull($hr, "W bazie brakuje użytkownika hr"); $this->loginAs($hr, 'user'); $client = $this->makeClient(); $content1 = $this->fetchContent('/admin/polcode/recruitment/employee/list', false, true); $content2 = $this->fetchContent('/admin/polcode/recruitment/am/list', false, true); $content2 = $this->fetchContent('/admin/polcode/recruitment/project/list', false, true); }
/** * @param $username * @return User * @throws InstanceNotFoundException */ protected function getUserFromUsername($username) { $user = $this->userManager->findUserByUsername($username); if (!$user) { throw new InstanceNotFoundException("User with the given username was not found: {$username}", 404); } return $user; }
/** * @Then the password for user ":username" should be ":password" * * @param $username * @param $password */ public function thePasswordForUserShouldBe($username, $password) { $user = $this->userManager->findUserByUsername($username); if (null === $user) { throw new \InvalidArgumentException(sprintf('No user with username %s can be found', $username)); } $encoder = $this->encoderFactory->getEncoder($user); $valid = $encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt()); PHPUnit::assertTrue($valid, sprintf('The password for user %s does not match %s', $username, $password)); }