Пример #1
0
 /**
  * Instantiate and configure the node according to this definition
  *
  * @return Faker\Components\Engine\Common\Composite\TypeNode The node instance
  *
  * @throws InvalidDefinitionException When the definition is invalid
  */
 public function getNode()
 {
     $type = new Names($this->database);
     $type->setGenerator($this->generator);
     $type->setUtilities($this->utilities);
     $type->setLocale($this->locale);
     foreach ($this->attributes as $attribute => $value) {
         $type->setOption($attribute, $value);
     }
     return new TypeNode('Names', $this->eventDispatcher, $type);
 }
Пример #2
0
 public function testGenerate()
 {
     $utilities = $this->getMockBuilder('Faker\\Components\\Engine\\Common\\Utilities')->disableOriginalConstructor()->getMock();
     $generator = $this->getMock('\\PHPStats\\Generator\\GeneratorInterface');
     $locale = $this->getMock('\\Faker\\Locale\\LocaleInterface');
     $database = $this->getProject()->getGeneratorDatabase();
     $generator->expects($this->exactly(6))->method('generate')->with($this->equalTo(0), $this->anything())->will($this->returnValue(0));
     $type = new Names($database);
     $type->setGenerator($generator);
     $type->setLocale($locale);
     $type->setUtilities($utilities);
     $type->setOption('format', '{fname} {lname}');
     $type->validate();
     $values = array();
     $this->assertEquals('Kristina Chung', $type->generate(1, $values));
     $type->setOption('format', '{fname} {inital} {lname}');
     $type->validate();
     $this->assertEquals('Kristina H Chung', $type->generate(1, $values));
     $type->setOption('format', '{fname},{inital} {lname}');
     $type->validate();
     $this->assertEquals('Kristina,H Chung', $type->generate(1, $values));
     $type->setOption('format', '{fname},{lname} {inital}');
     $type->validate();
     $this->assertEquals('Kristina,Chung H', $type->generate(1, $values));
     $type->setOption('format', '{lname}');
     $type->validate();
     $this->assertEquals('Chung', $type->generate(1, $values));
     $type->setOption('format', '{fname},{lname} {inital}');
     $type->validate();
     $this->assertEquals('Kristina,Chung H', $type->generate(1, $values));
 }