Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[DoctrineBridge] fixed the refreshing of the user for invalid users
  • Loading branch information
stof committed Dec 12, 2011
1 parent 257351a commit 9c1fbb8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
Expand Up @@ -75,7 +75,6 @@ public function refreshUser(UserInterface $user)
if (!$user instanceof $this->class) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
}


// The user must be reloaded via the primary key as all other data
// might have changed without proper persistence in the database.
Expand All @@ -89,7 +88,11 @@ public function refreshUser(UserInterface $user)
);
}

return $this->repository->find($id);
if (null === $refreshedUser = $this->repository->find($id)) {
throw new UsernameNotFoundException(sprintf('User with id %s not found', json_encode($id)));
}

return $refreshedUser;
}

/**
Expand Down
Expand Up @@ -40,21 +40,41 @@ public function testRefreshUserGetsUserByPrimaryKey()

$this->assertSame($user1, $provider->refreshUser($user1));
}

public function testRefreshUserRequiresId()
{
$em = $this->createTestEntityManager();

$user1 = new CompositeIdentEntity(null, null, 'user1');
$provider = new EntityUserProvider($em, 'Symfony\Tests\Bridge\Doctrine\Fixtures\CompositeIdentEntity', 'name');

$this->setExpectedException(
'InvalidArgumentException',
'You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine'
);
$provider->refreshUser($user1);
}

public function testRefreshInvalidUser()
{
$em = $this->createTestEntityManager();
$this->createSchema($em);

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

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

$provider = new EntityUserProvider($em, 'Symfony\Tests\Bridge\Doctrine\Fixtures\CompositeIdentEntity', 'name');

$user2 = new CompositeIdentEntity(1, 2, 'user2');
$this->setExpectedException(
'Symfony\Component\Security\Core\Exception\UsernameNotFoundException',
'User with id {"id1":1,"id2":2} not found'
);
$provider->refreshUser($user2);
}

private function createSchema($em)
{
$schemaTool = new SchemaTool($em);
Expand Down

0 comments on commit 9c1fbb8

Please sign in to comment.