1
0
mirror of https://github.com/fzaninotto/Faker.git synced 2025-04-21 16:01:56 +02:00

Merge pull request #1747 from aanfarhan/master

Add lastName gender specific on ru_RU locale
This commit is contained in:
Francois Zaninotto 2019-09-03 09:07:55 +02:00 committed by GitHub
commit 9979692c5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 0 deletions

View File

@ -105,6 +105,8 @@ class Person extends \Faker\Provider\Person
'Меркушев', 'Лыткин', 'Туров',
);
protected static $lastNameSuffix = array('a', '');
/**
* Return male middle name
*
@ -154,4 +156,24 @@ class Person extends \Faker\Provider\Person
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);
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace Faker\Test\Provider\ru_RU;
use Faker\Generator;
use Faker\Provider\ru_RU\Person;
use PHPUnit\Framework\TestCase;
class PersonTest extends TestCase
{
/**
* @var Generator
*/
private $faker;
public function setUp()
{
$faker = new Generator();
$faker->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());
}
}