covers edge case for Luhn
This commit is contained in:
parent
64bf80c2bb
commit
b1f190fd6c
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -102,6 +102,8 @@ class LuhnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
return array(
|
||||
array('1234567812345678'),
|
||||
array('4222222222222222'),
|
||||
array('0000000000000000'),
|
||||
array(0),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user