菜谱项目

PersonTest.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Faker\Test\Provider\sv_SE;
  3. use Faker\Calculator\Luhn;
  4. use Faker\Generator;
  5. use Faker\Provider\sv_SE\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 Person($faker));
  14. $this->faker = $faker;
  15. }
  16. public function provideSeedAndExpectedReturn()
  17. {
  18. return array(
  19. array(1, '720727', '720727-5798'),
  20. array(2, '710414', '710414-5664'),
  21. array(3, '591012', '591012-4519'),
  22. array(4, '180307', '180307-0356'),
  23. array(5, '820904', '820904-7748')
  24. );
  25. }
  26. /**
  27. * @dataProvider provideSeedAndExpectedReturn
  28. */
  29. public function testPersonalIdentityNumberUsesBirthDateIfProvided($seed, $birthdate, $expected)
  30. {
  31. $faker = $this->faker;
  32. $faker->seed($seed);
  33. $pin = $faker->personalIdentityNumber(\DateTime::createFromFormat('ymd', $birthdate));
  34. $this->assertEquals($expected, $pin);
  35. }
  36. public function testPersonalIdentityNumberGeneratesLuhnCompliantNumbers()
  37. {
  38. $pin = str_replace('-', '', $this->faker->personalIdentityNumber());
  39. $this->assertTrue(Luhn::isValid($pin));
  40. }
  41. public function testPersonalIdentityNumberGeneratesOddValuesForMales()
  42. {
  43. $pin = $this->faker->personalIdentityNumber(null, 'male');
  44. $this->assertEquals(1, $pin{9} % 2);
  45. }
  46. public function testPersonalIdentityNumberGeneratesEvenValuesForFemales()
  47. {
  48. $pin = $this->faker->personalIdentityNumber(null, 'female');
  49. $this->assertEquals(0, $pin{9} % 2);
  50. }
  51. }