diff --git a/src/Faker/Provider/ru_RU/Person.php b/src/Faker/Provider/ru_RU/Person.php index 25ebd5a185..e02113d1a6 100644 --- a/src/Faker/Provider/ru_RU/Person.php +++ b/src/Faker/Provider/ru_RU/Person.php @@ -105,6 +105,8 @@ class Person extends \Faker\Provider\Person 'Меркушев', 'Лыткин', 'Туров', ); + protected static $lastNameSuffix = array('a', ''); + /** * Return male middle name * @@ -154,4 +156,24 @@ public function middleName($gender = null) static::GENDER_FEMALE, ))); } + + /** + * Return last name for the specified gender. + * + * @param string|null $gender A gender of the last name should be generated + * for. If the argument is skipped a random gender will be used. + * @return string Last name + */ + public function lastName($gender = null) + { + $lastName = static::randomElement(static::$lastName); + + if (static::GENDER_FEMALE === $gender) { + return $lastName . 'a'; + } elseif (static::GENDER_MALE === $gender) { + return $lastName; + } + + return $lastName . static::randomElement(static::$lastNameSuffix); + } } diff --git a/test/Faker/Provider/ru_RU/PersonTest.php b/test/Faker/Provider/ru_RU/PersonTest.php new file mode 100644 index 0000000000..51976d5f3e --- /dev/null +++ b/test/Faker/Provider/ru_RU/PersonTest.php @@ -0,0 +1,37 @@ +addProvider(new Person($faker)); + $this->faker = $faker; + } + + public function testLastNameFemale() + { + $this->assertEquals("a", substr($this->faker->lastName('female'), -1)); + } + + public function testLastNameMale() + { + $this->assertNotEquals("a", substr($this->faker->lastName('male'), -1)); + } + + public function testLastNameRandom() + { + $this->assertNotNull($this->faker->lastName()); + } +}