Skip to content

Commit

Permalink
Fix negative mod confusion when generating random tckn's
Browse files Browse the repository at this point in the history
  • Loading branch information
deligoez committed Sep 12, 2019
1 parent d90ae7c commit 580929f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to `TCKimlikNo` will be documented in this file.

-

## Version 1.4.1 - 2019-09-12

- Fix php negative mod confusion to generate random tckn's

## Version 1.4.0 - 2019-09-05

- Laravel 6 Support
Expand Down
4 changes: 4 additions & 0 deletions src/TCKimlikNo.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public static function generateChecksumDigits($tcKimlikNo): string
$digit10 = ($oddDigitsSum * 7 - $evenDigitsSum) % 10;
$digit11 = ($oddDigitsSum + $evenDigitsSum + $digit10) % 10;

if ($digit10 < 0) {
$digit10 += 10;
}

return $digit10.$digit11;
}
}
13 changes: 13 additions & 0 deletions tests/Provider/TCKimlikNoFakerProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,17 @@ public function it_can_generate_a_valid_tckn()

$this->assertEquals(11, strlen($faker->tckn));
}

/** @test */
public function it_can_generate_too_many_valid_tckns()
{
$this->markTestSkipped();

$faker = Factory::create();
$faker->addProvider(new TCKimlikNoFakerProvider($faker));

for ($x = 0; $x <= 1000000; $x++) {
$this->assertEquals(11, strlen($faker->tckn));
}
}
}

0 comments on commit 580929f

Please sign in to comment.