Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

only test available date range on 32-bit #1348

Merged
merged 1 commit into from
Nov 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions test/Faker/Provider/fi_FI/PersonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,25 @@ public function testPersonalIdentityNumberUsesBirthDateIfProvided($seed, $birthd

public function testPersonalIdentityNumberGeneratesCompliantNumbers()
{
for ($i = 0; $i < 10; $i++) {
$birthdate = $this->faker->dateTimeBetween('1800-01-01 00:00:00', '1899-12-31 23:59:59');
$pin = $this->faker->personalIdentityNumber($birthdate);
$this->assertRegExp('/^[0-9]{6}\+[0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/', $pin);
if (strtotime('1800-01-01 00:00:00')) {
$min="1900";
$max="2099";
for ($i = 0; $i < 10; $i++) {
$birthdate = $this->faker->dateTimeBetween('1800-01-01 00:00:00', '1899-12-31 23:59:59');
$pin = $this->faker->personalIdentityNumber($birthdate, NULL, true);
$this->assertRegExp('/^[0-9]{6}\+[0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/', $pin);
}
} else { // timestamp limit for 32-bit computer
$min="1902";
Copy link
Owner

Choose a reason for hiding this comment

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

why not 1900?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because strtotime("1900...") return false on 32-bit

Copy link
Contributor Author

@remicollet remicollet Nov 10, 2017

Choose a reason for hiding this comment

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

# php -r 'var_dump(strtotime("1900-01-01"));'
bool(false)
# php -r 'var_dump(strtotime("1902-01-01"));'
int(-2145916800)
# php -r 'var_dump(strtotime("2038-01-01"));'
int(2145916800)
# php -r 'var_dump(strtotime("2039-01-01"));'
bool(false)

Copy link
Owner

Choose a reason for hiding this comment

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

Understood. According to http://php.net/manual/en/function.strtotime.php, the safe limits are 1902 and 2037. So why 2036 in your code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2036 was a typo ;)

$max="2037";
}
for ($i = 0; $i < 10; $i++) {
$birthdate = $this->faker->dateTimeBetween('1900-01-01 00:00:00', '1999-12-31 23:59:59');
$birthdate = $this->faker->dateTimeBetween("$min-01-01 00:00:00", '1999-12-31 23:59:59');
$pin = $this->faker->personalIdentityNumber($birthdate);
$this->assertRegExp('/^[0-9]{6}-[0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/', $pin);
}
for ($i = 0; $i < 10; $i++) {
$birthdate = $this->faker->dateTimeBetween('2000-01-01 00:00:00', '2099-12-31 23:59:59');
$birthdate = $this->faker->dateTimeBetween('2000-01-01 00:00:00', "$max-12-31 23:59:59");
$pin = $this->faker->personalIdentityNumber($birthdate);
$this->assertRegExp('/^[0-9]{6}A[0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/', $pin);
}
Expand Down