How to use NameGenerator class

Best Prophecy code snippet using NameGenerator

OrganizationGenerator.php

Source:OrganizationGenerator.php Github

copy

Full Screen

2namespace App;3use Exception;4class OrganizationGenerator5{6 public function generate(NameGenerator $nameGenerator, string $type = 'random')7 {8 $organization = new Organization();9 if ($type == 'random') {10 $organization->type = $this->randomType();11 } elseif ($type == 'adventuring company') {12 $organization->type = new AdventuringCompany();13 } elseif ($type == 'artisan guild') {14 $profession = random_item(Profession::load('crafter'));15 $organization->type = new ArtisanGuild($profession);16 } elseif ($type == 'holy order') {17 $organization->type = new HolyOrder();18 } elseif ($type == 'mercenary company') {19 $organization->type = new MercenaryCompany();20 } elseif ($type == 'wizard school') {21 $charGen = new CharacterGenerator();22 $nameGenerator = NameGenerator::defaultFantasy();23 $species = random_item(Species::load('race'));24 $founder = $charGen->generate($nameGenerator, $species, ['elderly']);25 $founder->profession = Profession::load('wizard');26 $founderTitle = new Title('Archmage', 'Archmage', '', '', 'wizard school', 5);27 $founder->titles [] = $founderTitle;28 if ($founder->primary_title == '') {29 $founder->primary_title = $founderTitle->getPrefix($founder->gender);30 }31 return new WizardSchool($founder);32 } else {33 throw new Exception('tried to get nonexistent organization type');34 }35 $organization->number_of_members = mt_rand($organization->type->min_size, $organization->type->max_size);36 $organization->size = $organization->getSizeClass();37 $organization->name = $organization->type->generateName();38 $organization->primary_trait = $this->randomTrait($organization->type->possible_traits);39 $organization->leaders = [];40 $organization->leaders = $this->generateLeaders($nameGenerator, $organization);41 $organization->notable_members = [];42 $organization->notable_members = $this->generateNotableMembers($nameGenerator, $organization);43 $organization->description = $organization->describe();44 return $organization;45 }46 private function generateLeaders(NameGenerator $nameGenerator, Organization $organization): array47 {48 $leaders = [];49 $leaderTitle = $organization->type->leadership_type->title;50 $leaderAgeCategories = $organization->getLeaderAgeCategories();51 $minLeaders = $organization->type->leadership_type->min_leaders;52 $maxLeaders = $organization->type->leadership_type->max_leaders;53 $numberOfLeaders = mt_rand($minLeaders, $maxLeaders);54 $charGen = new CharacterGenerator();55 $species = Species::randomRace();56 for ($i = 0; $i < $numberOfLeaders; $i++) {57 $leader = $charGen->generate($nameGenerator, $species, $leaderAgeCategories);58 $leader->profession = $organization->randomProfession();59 $leader->primary_title = $leaderTitle->getPrefix($leader->gender);60 $leader->titles = [$leaderTitle];61 $leaders [] = $leader;62 }63 return $leaders;64 }65 private function generateNotableMembers(NameGenerator $nameGenerator, Organization $organization): array66 {67 $members = [];68 $numberOfMembers = mt_rand(1, 4);69 $charGen = new CharacterGenerator();70 for ($i = 0; $i < $numberOfMembers; $i++) {71 $species = Species::randomRace();72 $rank = $organization->getRandomMemberRank();73 $member = $charGen->generate($nameGenerator, $species, $rank->possible_age_categories);74 $member->profession = $organization->randomProfession();75 $title = $rank->title;76 $member->titles = [$title];77 $member->primary_title = $title->getPrefix($member->gender);78 $members [] = $member;79 }80 return $members;81 }82 private function randomTrait(array $traits): string83 {84 return random_item($traits);85 }86 private function randomType(): OrganizationType87 {88 $types = [89 'adventuring company',90 'artisan guild',91 'holy order',92 'mercenary company',93 'wizard school',94 ];95 $type = random_item($types);96 if ($type == 'adventuring company') {97 return new AdventuringCompany();98 } else if ($type == 'artisan guild') {99 $profession = random_item(Profession::load('crafter'));100 return new ArtisanGuild($profession);101 } else if ($type == 'holy order') {102 return new HolyOrder();103 } else if ($type == 'mercenary company') {104 return new MercenaryCompany();105 } else if ($type == 'wizard school') {106 $charGen = new CharacterGenerator();107 $nameGenerator = NameGenerator::defaultFantasy();108 $species = random_item(Species::load('race'));109 $founder = $charGen->generate($nameGenerator, $species, ['elderly']);110 return new WizardSchool($founder);111 }112 }113}...

Full Screen

Full Screen

NameGeneratorTest.php

Source:NameGeneratorTest.php Github

copy

Full Screen

...5 *6 * @license LGPL-3.0-or-later7 */8namespace LiveWorksheet\Parser\Tests\Parameter\ExpressionLanguage\SequentialRandom;9use LiveWorksheet\Parser\Parameter\ExpressionLanguage\SequentialRandom\NameGenerator;10use PHPUnit\Framework\TestCase;11class NameGeneratorTest extends TestCase12{13 public function testGeneratesRandomNames(): void14 {15 $generator = new NameGenerator(1);16 // female17 self::assertEquals('Sabine', $generator->next('f'));18 self::assertEquals('Katrin', $generator->next('f'));19 // male20 self::assertEquals('Paul', $generator->next('m'));21 self::assertEquals('Martin', $generator->next('m'));22 // mixed23 self::assertEquals('Sandra', $generator->next('f,m'));24 self::assertEquals('Alexander', $generator->next('f,m'));25 // invalid26 self::assertEquals('?', $generator->next(''));27 self::assertEquals('?', $generator->next('abc'));28 }29 public function testGeneratesSequentialRandomNames(): void30 {31 $generator1 = new NameGenerator(123, 'foo');32 $generator2 = new NameGenerator(123, 'foo');33 $names = [];34 for ($i = 0; $i < 60; ++$i) {35 $names[] = $generator1->next('f,m');36 }37 NameGenerator::reset(123);38 foreach ($names as $name) {39 self::assertEquals($name, $generator2->next('f,m'));40 }41 }42 public function testReset(): void43 {44 $value1 = (new NameGenerator(10))->next('f');45 $value2 = (new NameGenerator(20))->next('f');46 // Only reset seed '10'47 NameGenerator::reset(10);48 self::assertEquals($value1, (new NameGenerator(10))->next('f'));49 self::assertNotEquals($value2, (new NameGenerator(20))->next('f'));50 // Reset all51 NameGenerator::reset();52 self::assertEquals($value2, (new NameGenerator(20))->next('f'));53 }54 public function testNamesAreUniqueAcrossSeed(): void55 {56 $generator1 = new NameGenerator(3, 'foo');57 $generator2 = new NameGenerator(3, 'bar');58 $names = [];59 for ($i = 0; $i < 29; ++$i) {60 $name = $generator1->next('f,m');61 self::assertNotContains($name, $names);62 $names[] = $name;63 $name = $generator2->next('f,m');64 self::assertNotContains($name, $names);65 $names[] = $name;66 }67 }68}...

Full Screen

Full Screen

robot-name.php

Source:robot-name.php Github

copy

Full Screen

1<?php2class Robot3{4 private $name;5 /** @var null|\NameGenerator */6 private $nameGenerator;7 /**8 * @param null|\NameGenerator $nameGenerator9 */10 public function __construct(\NameGenerator $nameGenerator = null)11 {12 if (null === $nameGenerator) {13 $nameGenerator = new \RobotNameGenerator;14 }15 $this->nameGenerator = $nameGenerator;16 }17 /**18 * @return string19 */20 public function getName()21 {22 if (null === $this->name) {23 $this->name = $this->nameGenerator->generateName();24 }25 return $this->name;26 }27 public function reset()28 {29 $this->name = null;30 }31}32interface NameGenerator33{34 public function generateName();35}36class RobotNameGenerator implements NameGenerator37{38 const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';39 protected static $robotCount = 0;40 41 /**42 * @return string43 */44 public function generateName()45 {46 $name = $this->getChars() . $this->getNums();47 static::$robotCount++;48 return $name;49 }50 private function getChars()...

Full Screen

Full Screen

NameGenerator

Using AI Code Generation

copy

Full Screen

1include_once('NameGenerator.php');2$ng = new NameGenerator();3echo $ng->getName();4include_once('NameGenerator.php');5$ng = new NameGenerator();6echo $ng->getName();7include_once('NameGenerator.php');8$ng = new NameGenerator();9echo $ng->getName();10include_once('NameGenerator.php');11$ng = new NameGenerator();12echo $ng->getName();13include_once('NameGenerator.php');14$ng = new NameGenerator();15echo $ng->getName();16include_once('NameGenerator.php');17$ng = new NameGenerator();18echo $ng->getName();19include_once('NameGenerator.php');20$ng = new NameGenerator();21echo $ng->getName();22include_once('NameGenerator.php');23$ng = new NameGenerator();24echo $ng->getName();25include_once('NameGenerator.php');26$ng = new NameGenerator();27echo $ng->getName();28include_once('NameGenerator.php');29$ng = new NameGenerator();30echo $ng->getName();31include_once('NameGenerator.php');32$ng = new NameGenerator();33echo $ng->getName();34include_once('NameGenerator.php');35$ng = new NameGenerator();36echo $ng->getName();37include_once('NameGenerator.php');38$ng = new NameGenerator();39echo $ng->getName();40include_once('NameGenerator

Full Screen

Full Screen

NameGenerator

Using AI Code Generation

copy

Full Screen

1$obj = new NameGenerator();2$obj->getName();3$obj = new NameGenerator();4$obj->getName();5$obj = new NameGenerator();6$obj->getName();7$obj = new NameGenerator();8$obj->getName();9$obj = new NameGenerator();10$obj->getName();11$obj = new NameGenerator();12$obj->getName();13$obj = new NameGenerator();14$obj->getName();15$obj = new NameGenerator();16$obj->getName();17$obj = new NameGenerator();18$obj->getName();19$obj = new NameGenerator();20$obj->getName();21$obj = new NameGenerator();22$obj->getName();23$obj = new NameGenerator();24$obj->getName();25$obj = new NameGenerator();26$obj->getName();27$obj = new NameGenerator();28$obj->getName();29$obj = new NameGenerator();30$obj->getName();31$obj = new NameGenerator();32$obj->getName();

Full Screen

Full Screen

NameGenerator

Using AI Code Generation

copy

Full Screen

1require_once 'Prophecy/NameGenerator.php';2$generator = new NameGenerator();3echo $generator->getFirstName();4echo $generator->getLastName();5require_once 'Prophecy/NameGenerator.php';6$generator = new NameGenerator();7echo $generator->getFirstName();8echo $generator->getLastName();9require_once 'Prophecy/NameGenerator.php';10$generator = new NameGenerator();11echo $generator->getFirstName();12echo $generator->getLastName();13require_once 'Prophecy/NameGenerator.php';14$generator = new NameGenerator();15echo $generator->getFirstName();16echo $generator->getLastName();17require_once 'Prophecy/NameGenerator.php';18$generator = new NameGenerator();19echo $generator->getFirstName();20echo $generator->getLastName();21require_once 'Prophecy/NameGenerator.php';22$generator = new NameGenerator();23echo $generator->getFirstName();24echo $generator->getLastName();25require_once 'Prophecy/NameGenerator.php';26$generator = new NameGenerator();27echo $generator->getFirstName();28echo $generator->getLastName();29require_once 'Prophecy/NameGenerator.php';30$generator = new NameGenerator();31echo $generator->getFirstName();32echo $generator->getLastName();33require_once 'Prophecy/NameGenerator.php';34$generator = new NameGenerator();35echo $generator->getFirstName();36echo $generator->getLastName();37require_once 'Prophecy/NameGenerator.php';38$generator = new NameGenerator();

Full Screen

Full Screen

NameGenerator

Using AI Code Generation

copy

Full Screen

1require_once 'ProphecyGenerator.php';2$prophecy = new ProphecyGenerator();3echo $prophecy->getNameGenerator()->getName();4require_once 'ProphecyGenerator.php';5$prophecy = new ProphecyGenerator();6echo $prophecy->getNameGenerator()->getName();7require_once 'ProphecyGenerator.php';8$prophecy = new ProphecyGenerator();9echo $prophecy->getNameGenerator()->getName();10require_once 'ProphecyGenerator.php';11$prophecy = new ProphecyGenerator();12echo $prophecy->getNameGenerator()->getName();13require_once 'ProphecyGenerator.php';14$prophecy = new ProphecyGenerator();15echo $prophecy->getNameGenerator()->getName();16require_once 'ProphecyGenerator.php';17$prophecy = new ProphecyGenerator();18echo $prophecy->getNameGenerator()->getName();19require_once 'ProphecyGenerator.php';20$prophecy = new ProphecyGenerator();21echo $prophecy->getNameGenerator()->getName();22require_once 'ProphecyGenerator.php';23$prophecy = new ProphecyGenerator();24echo $prophecy->getNameGenerator()->getName();25require_once 'ProphecyGenerator.php';26$prophecy = new ProphecyGenerator();27echo $prophecy->getNameGenerator()->getName();28require_once 'ProphecyGenerator.php';29$prophecy = new ProphecyGenerator();30echo $prophecy->getNameGenerator()->getName();31require_once 'ProphecyGenerator.php';32$prophecy = new ProphecyGenerator();33echo $prophecy->getNameGenerator()->getName();

Full Screen

Full Screen

NameGenerator

Using AI Code Generation

copy

Full Screen

1require_once 'NameGenerator.php';2use Prophecy\NameGenerator;3$ng = new NameGenerator();4echo $ng->generateName();5require_once 'NameGenerator.php';6use Prophecy\NameGenerator;7$ng = new NameGenerator();8echo $ng->generateName();9require_once 'NameGenerator.php';10use Prophecy\NameGenerator;11$ng = new NameGenerator();12echo $ng->generateName();13require_once 'NameGenerator.php';14use Prophecy\NameGenerator;15$ng = new NameGenerator();16echo $ng->generateName();17require_once 'NameGenerator.php';18use Prophecy\NameGenerator;19$ng = new NameGenerator();20echo $ng->generateName();21require_once 'NameGenerator.php';22use Prophecy\NameGenerator;23$ng = new NameGenerator();24echo $ng->generateName();25require_once 'NameGenerator.php';26use Prophecy\NameGenerator;27$ng = new NameGenerator();28echo $ng->generateName();29require_once 'NameGenerator.php';30use Prophecy\NameGenerator;31$ng = new NameGenerator();32echo $ng->generateName();33require_once 'NameGenerator.php';34use Prophecy\NameGenerator;

Full Screen

Full Screen

NameGenerator

Using AI Code Generation

copy

Full Screen

1$ng = new NameGenerator();2echo $ng->getName();3{4}5{6 public $model;7 public function getModel()8 {9 return "The car model is " . $this->model;10 }11}12{13}14$SportsCar1 = new SportsCar();15$SportsCar1 ->model = "Mercedes";16echo $SportsCar1 ->getModel();17{18}19{20}21{22 public $model;23 public function getModel()24 {25 return "The car model is " . $this->model;26 }27}28{29 public function getModel()30 {31 return "The car model is " . $this->model;32 }33}34$SportsCar1 = new SportsCar();35$SportsCar1 ->model = "Mercedes";36echo $SportsCar1 ->getModel();37In the above example, we have created a parent class called Car and a child class called SportsCar. The child class SportsCar overrides the method getModel() of

Full Screen

Full Screen

NameGenerator

Using AI Code Generation

copy

Full Screen

1require_once('NameGenerator.php');2$ng = new NameGenerator();3echo $ng->getFullName();4require_once('NameGenerator.php');5$ng = new Prophecy\NameGenerator();6echo $ng->getFullName();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Prophecy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in NameGenerator

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful