PHP code example of rasuvaeff / property-testing-names
1. Go to this page and download the library: Download rasuvaeff/property-testing-names library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rasuvaeff / property-testing-names example snippets
use Rasuvaeff\PropertyTesting\Names\Names;
use Rasuvaeff\PropertyTesting\Names\Gender;
$firstNames = Names::first(); // 'Ian', 'Emma', …
$surnames = Names::last(locale: 'ru'); // 'Попов', 'Иванова', …
$femaleNames = Names::first('ru', Gender::Female); // 'Мария', 'Ольга', …
$patronymics = Names::middle('ru'); // 'Ивановна', 'Петрович', …
$displayNames = Names::full('ru', middle: true); // 'Иван Иванович Иванов'
$people = Names::person('ru', middle: true); // PersonName objects
Gen::sample($displayNames, 3, 6); // fixed seed → the same three names every time
use Rasuvaeff\PropertyTesting\ArbitraryInterface;
use Rasuvaeff\PropertyTesting\Names\Names;
use Rasuvaeff\PropertyTesting\Property;
use Testo\Assert;
#[Property(runs: 300)]
public function displayNameFitsTheColumn(string $first, string $last): void
{
Assert::true(mb_strlen((new Profile($first, $last))->displayName()) <= 255);
}
/** @return array<string, ArbitraryInterface> */
public static function displayNameFitsTheColumnGenerators(): array
{
return [
'first' => Names::first(locale: 'ru'),
'last' => Names::last(locale: 'ru'),
];
}
Gen::map(Names::person(), static fn (PersonName $p): string => $p->last . ', ' . $p->first);
Gen::forClass(Profile::class, ['name' => Names::person('ru', middle: true)]);
foreach (Names::locales() as $locale) {
// one property run per supported locale
}
$person = Names::person('ru', middle: true); // Мария Ивановна Иванова