Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Add lastName gender specific on ru_RU locale #1747

Merged
merged 11 commits into from
Sep 3, 2019
19 changes: 19 additions & 0 deletions src/Faker/Provider/ru_RU/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,23 @@ public function middleName($gender = null)
static::GENDER_FEMALE,
)));
}

/**
* Return last name for the specified gender.
*
* @access public
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if using the @access annotation here is something we really need - it duplicates the public visibility keyword that is already present. Can we remove it?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, please remove it

* @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)
Copy link
Owner

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

{
$lastName = static::randomElement(static::$lastName);

if (static::GENDER_FEMALE === $gender) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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';
}

return $lastName;
}
}
32 changes: 32 additions & 0 deletions test/Faker/Provider/ru_RU/PersonTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visibility should be protected here, but we can - with the right rules - automatically fix.

{
$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(), -1));
}
}