-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Austrian social security number generation #88
Conversation
Signed-off-by: Daniel Schmelz <daniel@schmelz.org>
// consecutive number must be between 100 and 999 | ||
$consecutiveNumber = substr($number, 0, 3); | ||
$this->assertGreaterThanOrEqual(100, $consecutiveNumber); | ||
$this->assertLessThanOrEqual(999, $consecutiveNumber); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add an assertion for the checksum number? Just in case someone will refactor it in the future and the checksum will no longer be valid. This is done for Polish PESEL number too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought about that too, but couldn't find a way to test the verification number without just copying the production verification number generation (which I have done now).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest an associate array here with birthdates and the expected outputs. A bit like a test matrix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the problem here is that the birth date is taken together with a (randomly generated) consecutive number to calculate the check number, meaning we can't just run through a data provider..unless we also take the consecutive number as optional ssn()
parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or I could put the check number generation in an own public method that can then be tested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, for the generation logic the random number can just be ignored using substr
, or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess that's solved with the ea4cf10.
Signed-off-by: Daniel Schmelz <daniel@schmelz.org>
|
||
// Verification number is correct | ||
$verificationNumber = substr($number, 3, 1); | ||
$correctVerificationNumber = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use an array to simplify the calculation:
$weights = [3, 7, 9, 0, 5, 8, 4, 2, 1, 6];
$checkSum = 0;
foreach ($weights as $i => $weight) {
$checkSum += (int) $number[$i] * $weight;
}
self::assertEquals($number[3], $checkSum % 11);
You may also want to extract this logic to a separate method like assertValidSsn
and reuse in the other test method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, added the verification number check the other test method too.
Signed-off-by: Daniel Schmelz <daniel@schmelz.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks! |
See discussion in #79.
This PR: