Fix PasswordToken constraint

This commit is contained in:
Romain Neutron
2013-05-03 01:25:48 +02:00
parent 96a0a14552
commit 993b219cc1
4 changed files with 7 additions and 7 deletions

View File

@@ -31,11 +31,11 @@ class PasswordToken extends Constraint
public function isValid($token)
{
try {
$datas = $this->random->helloToken($this->app, $token);
$data = $this->random->helloToken($token);
} catch (\Exception_NotFound $e) {
return false;
}
return \random::TYPE_PASSWORD === $datas['type'];
return \random::TYPE_PASSWORD === $data['type'];
}
}

View File

@@ -21,7 +21,7 @@ class PasswordTokenValidator extends ConstraintValidator
*/
public function validate($value, Constraint $constraint)
{
if ($constraint->isValid($value)) {
if (!$constraint->isValid($value)) {
$this->context->addViolation('The token provided is not valid anymore');
}
}

View File

@@ -19,7 +19,7 @@ class PasswordTokenTest extends \PhraseanetPHPUnitAbstract
$random
->expects($this->once())
->method('helloToken')
->with(self::$DI['app'], $token)
->with($token)
->will($this->throwException(new \Exception_NotFound('Token not found')));
$constraint = new PasswordToken(self::$DI['app'], $random);
@@ -39,7 +39,7 @@ class PasswordTokenTest extends \PhraseanetPHPUnitAbstract
$random
->expects($this->once())
->method('helloToken')
->with(self::$DI['app'], $token)
->with($token)
->will($this->returnValue(array('usr_id' => mt_rand(), 'type' => \random::TYPE_PASSWORD)));
$constraint = new PasswordToken(self::$DI['app'], $random);

View File

@@ -13,10 +13,10 @@ class PasswordTokenValidatorTest extends \PhraseanetPHPUnitAbstract
{
$context = $this->getMock('Symfony\Component\Validator\ExecutionContextInterface');
$builder = $context
->expects($this->exactly($isValid ? 1 : 0))
->expects($this->exactly($isValid ? 0 : 1))
->method('addViolation');
if ($isValid) {
if (!$isValid) {
$builder->with($this->isType('string'));
}