Skip to content

Commit

Permalink
fix #832 (#836)
Browse files Browse the repository at this point in the history
* fix #832

* review fixes
  • Loading branch information
gam6itko authored Jan 2, 2024
1 parent 0d61942 commit 93bcd9e
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased](https://github.com/FakerPHP/Faker/compare/v1.23.0...main)

- Fixed double `а` female lastName in `ru_RU/Person::name()` (#832)
- Fixed polish license plates (#685)
- Stopped using `static` in callables in `Provider\pt_BR\PhoneNumber` (#785)
- Fixed incorrect female name (#794)
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@
*
* @property string $lastName
*
* @method string lastName()
* @method string lastName($gender = null)
*
* @property string $title
*
Expand Down
26 changes: 17 additions & 9 deletions src/Faker/Provider/ru_RU/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
class Person extends \Faker\Provider\Person
{
protected static $maleNameFormats = [
'{{firstNameMale}} {{middleNameMale}} {{lastName}}',
'{{lastName}} {{firstNameMale}} {{middleNameMale}}',
'{{firstNameMale}} {{middleNameMale}} {{lastNameMale}}',
'{{lastNameMale}} {{firstNameMale}} {{middleNameMale}}',
];

/**
* This provider uses wikipedia's 250 top russian last names
* That list of MALE last names could be safely extended to FEMALE list just by adding 'a' letter at the end
*/
protected static $femaleNameFormats = [
'{{firstNameFemale}} {{middleNameFemale}} {{lastName}}а',
'{{lastName}}а {{firstNameFemale}} {{middleNameFemale}}',
'{{firstNameFemale}} {{middleNameFemale}} {{lastNameFemale}}',
'{{lastNameFemale}} {{firstNameFemale}} {{middleNameFemale}}',
];

/**
Expand Down Expand Up @@ -165,16 +165,24 @@ public function middleName($gender = null)
*/
public function lastName($gender = null)
{
$lastName = static::randomElement(static::$lastName);

if (static::GENDER_FEMALE === $gender) {
return $lastName . 'а';
return $this->lastNameFemale();
}

if (static::GENDER_MALE === $gender) {
return $lastName;
return $this->lastNameMale();
}

return $lastName . static::randomElement(static::$lastNameSuffix);
return static::randomElement(static::$lastName) . static::randomElement(static::$lastNameSuffix);
}

public function lastNameMale(): string
{
return static::randomElement(static::$lastName);
}

public function lastNameFemale(): string
{
return static::randomElement(static::$lastName) . 'а';
}
}
138 changes: 136 additions & 2 deletions test/Faker/Provider/ru_RU/PersonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Faker\Test\Provider\ru_RU;

use Faker\Generator;
use Faker\Provider\ru_RU\Person;
use Faker\Test\TestCase;

Expand All @@ -10,12 +11,12 @@
*/
final class PersonTest extends TestCase
{
public function testLastNameFemale(): void
public function testLastNameForFemale(): void
{
self::assertEquals('а', substr($this->faker->lastName('female'), -2, 2));
}

public function testLastNameMale(): void
public function testLastNameForMale(): void
{
self::assertNotEquals('а', substr($this->faker->lastName('male'), -2, 2));
}
Expand All @@ -29,4 +30,137 @@ protected function getProviders(): iterable
{
yield new Person($this->faker);
}

/**
* @dataProvider dataLastNameMale
*/
public function testLastNameMale(int $seed, string $expected): void
{
$generator = new Generator();
$generator->seed($seed);

$provider = new Person($generator);

self::assertSame($expected, $provider->lastNameMale());
}

public function dataLastNameMale(): iterable
{
yield 'seed: 4' => [
4,
'Морозов',
];

yield 'seed: 8' => [
8,
'Гусев',
];

yield 'seed: 15' => [
15,
'Алексеев',
];

yield 'seed: 16' => [
16,
'Фадеев',
];

yield 'seed: 23' => [
23,
'Воронов',
];

yield 'seed: 42' => [
42,
'Горбачёв',
];
}

/**
* @dataProvider dataLastNameFemale
*/
public function testLastNameFemale(int $seed, string $expected): void
{
$generator = new Generator();
$generator->seed($seed);

$provider = new Person($generator);

self::assertSame($expected, $provider->lastNameFemale());
}

public function dataLastNameFemale(): iterable
{
yield 'seed: 4' => [
4,
'Морозова',
];

yield 'seed: 8' => [
8,
'Гусева',
];

yield 'seed: 15' => [
15,
'Алексеева',
];

yield 'seed: 16' => [
16,
'Фадеева',
];

yield 'seed: 23' => [
23,
'Воронова',
];

yield 'seed: 42' => [
42,
'Горбачёва',
];
}

/**
* Issue 832
*
* @dataProvider dataFemaleSurnameWithoutDoubleALetter
*/
public function testFemaleSurnameWithoutDoubleALetter(int $seed, string $expected): void
{
$generator = new Generator();
$generator->seed($seed);

foreach ($this->getProviders() as $provider) {
$generator->addProvider($provider);
}

self::assertSame($expected, $generator->name('female'));
}

public static function dataFemaleSurnameWithoutDoubleALetter(): iterable
{
//bad cases
yield 'seed: 55' => [
55,
'Ларионова Алиса Александровна',
];

yield 'seed: 512' => [
512,
'Тихонова Галина Андреевна',
];

yield 'seed: 625' => [
625,
'Ларионова Изабелла Романовна',
];

yield 'seed: 1917' => [
1917,
'Павлова Владлена Романовна',
];
}
}

0 comments on commit 93bcd9e

Please sign in to comment.