covers edge case for Luhn

This commit is contained in:
Ricard Clau 2013-01-06 22:18:36 +01:00
parent 64bf80c2bb
commit b1f190fd6c
2 changed files with 3 additions and 1 deletions

View File

@ -51,7 +51,7 @@ class LuhnValidator extends ConstraintValidator
$sum += (($i % 2) === $oddLength) ? array_sum(str_split($digit * 2)) : $digit;
}
if (($sum % 10) !== 0) {
if ($sum === 0 || ($sum % 10) !== 0) {
$this->context->addViolation($constraint->message);
}
}

View File

@ -102,6 +102,8 @@ class LuhnValidatorTest extends \PHPUnit_Framework_TestCase
return array(
array('1234567812345678'),
array('4222222222222222'),
array('0000000000000000'),
array(0),
);
}
}