-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add lastName gender specific on ru_RU locale #1747
Changes from all commits
a1ddd12
f71e973
176ae74
2a3a580
c01c36f
4eda000
63d5a01
c6d03aa
8d16af3
5d77af5
2919adc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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) { | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should add a link here for explanation? For example, https://en.m.wikipedia.org/wiki/Eastern_Slavic_naming_customs#Grammar. /cc @pimjansen There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, im not a fan of "only in our usecases" but it will do for no i guess |
||||||||||||
return $lastName . 'a'; | ||||||||||||
} elseif (static::GENDER_MALE === $gender) { | ||||||||||||
return $lastName; | ||||||||||||
} | ||||||||||||
|
||||||||||||
return $lastName . static::randomElement(static::$lastNameSuffix); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about
Suggested change
? Then we can also do away with the newly introduced |
||||||||||||
} | ||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Visibility should be |
||
{ | ||
$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()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand correctly or is the generated
lastName
always Male by default? Shouldn't it return a random gender?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, missed that one.
@aanfarhan
Can you adjust, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I'll add some adjustment to the code.