菜谱项目

PersonTest.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Faker\Test\Provider\fi_FI;
  3. use Faker\Generator;
  4. use Faker\Provider\DateTime;
  5. use Faker\Provider\fi_FI\Person;
  6. class PersonTest extends \PHPUnit_Framework_TestCase
  7. {
  8. /** @var Generator */
  9. protected $faker;
  10. public function setUp()
  11. {
  12. $faker = new Generator();
  13. $faker->addProvider(new DateTime($faker));
  14. $faker->addProvider(new Person($faker));
  15. $this->faker = $faker;
  16. }
  17. public function provideSeedAndExpectedReturn()
  18. {
  19. return array(
  20. array(1, '1800-01-01', '010100+5207'),
  21. array(2, '1930-08-08', '080830-508R'),
  22. array(3, '1999-12-31', '311299-409D'),
  23. array(4, '2000-01-01', '010100A039P'),
  24. array(5, '2015-06-17', '170615A690X')
  25. );
  26. }
  27. /**
  28. * @dataProvider provideSeedAndExpectedReturn
  29. */
  30. public function testPersonalIdentityNumberUsesBirthDateIfProvided($seed, $birthdate, $expected)
  31. {
  32. $faker = $this->faker;
  33. $faker->seed($seed);
  34. $pin = $faker->personalIdentityNumber(\DateTime::createFromFormat('Y-m-d', $birthdate));
  35. $this->assertEquals($expected, $pin);
  36. }
  37. public function testPersonalIdentityNumberGeneratesCompliantNumbers()
  38. {
  39. for ($i = 0; $i < 10; $i++) {
  40. $birthdate = $this->faker->dateTimeBetween('1800-01-01 00:00:00', '1899-12-31 23:59:59');
  41. $pin = $this->faker->personalIdentityNumber($birthdate);
  42. $this->assertRegExp('/^[0-9]{6}\+[0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/', $pin);
  43. }
  44. for ($i = 0; $i < 10; $i++) {
  45. $birthdate = $this->faker->dateTimeBetween('1900-01-01 00:00:00', '1999-12-31 23:59:59');
  46. $pin = $this->faker->personalIdentityNumber($birthdate);
  47. $this->assertRegExp('/^[0-9]{6}-[0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/', $pin);
  48. }
  49. for ($i = 0; $i < 10; $i++) {
  50. $birthdate = $this->faker->dateTimeBetween('2000-01-01 00:00:00', '2099-12-31 23:59:59');
  51. $pin = $this->faker->personalIdentityNumber($birthdate);
  52. $this->assertRegExp('/^[0-9]{6}A[0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/', $pin);
  53. }
  54. }
  55. public function testPersonalIdentityNumberGeneratesOddValuesForMales()
  56. {
  57. $pin = $this->faker->personalIdentityNumber(null, 'male');
  58. $this->assertEquals(1, $pin{9} % 2);
  59. }
  60. public function testPersonalIdentityNumberGeneratesEvenValuesForFemales()
  61. {
  62. $pin = $this->faker->personalIdentityNumber(null, 'female');
  63. $this->assertEquals(0, $pin{9} % 2);
  64. }
  65. }