PersonTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace Faker\Test\Provider;
  3. use Faker\Provider\Person;
  4. use Faker\Generator;
  5. use PHPUnit\Framework\TestCase;
  6. class PersonTest extends TestCase
  7. {
  8. /**
  9. * @dataProvider firstNameProvider
  10. */
  11. public function testFirstName($gender, $expected)
  12. {
  13. $faker = new Generator();
  14. $faker->addProvider(new Person($faker));
  15. $this->assertContains($faker->firstName($gender), $expected);
  16. }
  17. public function firstNameProvider()
  18. {
  19. return array(
  20. array(null, array('John', 'Jane')),
  21. array('foobar', array('John', 'Jane')),
  22. array('male', array('John')),
  23. array('female', array('Jane')),
  24. );
  25. }
  26. public function testFirstNameMale()
  27. {
  28. $this->assertContains(Person::firstNameMale(), array('John'));
  29. }
  30. public function testFirstNameFemale()
  31. {
  32. $this->assertContains(Person::firstNameFemale(), array('Jane'));
  33. }
  34. /**
  35. * @dataProvider titleProvider
  36. */
  37. public function testTitle($gender, $expected)
  38. {
  39. $faker = new Generator();
  40. $faker->addProvider(new Person($faker));
  41. $this->assertContains($faker->title($gender), $expected);
  42. }
  43. public function titleProvider()
  44. {
  45. return array(
  46. array(null, array('Mr.', 'Mrs.', 'Ms.', 'Miss', 'Dr.', 'Prof.')),
  47. array('foobar', array('Mr.', 'Mrs.', 'Ms.', 'Miss', 'Dr.', 'Prof.')),
  48. array('male', array('Mr.', 'Dr.', 'Prof.')),
  49. array('female', array('Mrs.', 'Ms.', 'Miss', 'Dr.', 'Prof.')),
  50. );
  51. }
  52. public function testTitleMale()
  53. {
  54. $this->assertContains(Person::titleMale(), array('Mr.', 'Dr.', 'Prof.'));
  55. }
  56. public function testTitleFemale()
  57. {
  58. $this->assertContains(Person::titleFemale(), array('Mrs.', 'Ms.', 'Miss', 'Dr.', 'Prof.'));
  59. }
  60. public function testLastNameReturnsDoe()
  61. {
  62. $faker = new Generator();
  63. $faker->addProvider(new Person($faker));
  64. $this->assertEquals($faker->lastName(), 'Doe');
  65. }
  66. public function testNameReturnsFirstNameAndLastName()
  67. {
  68. $faker = new Generator();
  69. $faker->addProvider(new Person($faker));
  70. $this->assertContains($faker->name(), array('John Doe', 'Jane Doe'));
  71. $this->assertContains($faker->name('foobar'), array('John Doe', 'Jane Doe'));
  72. $this->assertContains($faker->name('male'), array('John Doe'));
  73. $this->assertContains($faker->name('female'), array('Jane Doe'));
  74. }
  75. }