Skip to content
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

Merged
merged 3 commits into from
Nov 30, 2020
Merged

Improve Austrian social security number generation #88

merged 3 commits into from
Nov 30, 2020

Conversation

krsriq
Copy link

@krsriq krsriq commented Nov 30, 2020

See discussion in #79.

This PR:

  • Adds a new feature ...
  • Covered by tests
  • Fixes #nnnn

Signed-off-by: Daniel Schmelz <daniel@schmelz.org>
src/Faker/Provider/de_AT/Person.php Outdated Show resolved Hide resolved
src/Faker/Provider/de_AT/Person.php Outdated Show resolved Hide resolved
// consecutive number must be between 100 and 999
$consecutiveNumber = substr($number, 0, 3);
$this->assertGreaterThanOrEqual(100, $consecutiveNumber);
$this->assertLessThanOrEqual(999, $consecutiveNumber);

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.

Copy link
Author

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).

Copy link
Member

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.

Copy link
Author

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?

Copy link
Author

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?

Copy link
Member

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.

Copy link
Author

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 = (

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.

Copy link
Author

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>
@pimjansen pimjansen added the enhancement New feature or request label Nov 30, 2020
Copy link

@IonBazan IonBazan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@pimjansen pimjansen merged commit 2a0f6b7 into FakerPHP:main Nov 30, 2020
@pimjansen
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants