Пример #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 Email($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('Email', $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(2))->method('generate')->with($this->equalTo(0), $this->isType('integer'))->will($this->returnValue(0));
     $utilities->expects($this->exactly(2))->method('generateRandomAlphanumeric')->with($this->isType('string'), $this->isInstanceOf($generator), $this->isInstanceOf($locale))->will($this->onConsecutiveCalls('ddDDD', '1111'));
     $type = new Email($database);
     $type->setGenerator($generator);
     $type->setLocale($locale);
     $type->setUtilities($utilities);
     $type->setOption('format', '{fname}\'{lname}{alpha2}@{alpha1}.{domain}');
     $type->setOption('params', '{"alpha1":"ccCCC","alpha2":"xxxx"}');
     $type->validate();
     $values = array();
     $this->assertEquals('Kristina\'*****@*****.**', $type->generate(1, $values));
 }