Exemplo n.º 1
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');
     $type = new ClosureType();
     $type->setGenerator($generator);
     $type->setLocale($locale);
     $type->setUtilities($utilities);
     $type->setClosure(function ($rows, $values) {
         return 5;
     });
     $type->validate();
     $values = array();
     $this->assertEquals(5, $type->generate(1, $values));
     $this->assertEquals(5, $type->generate(1, $values));
     $this->assertEquals(5, $type->generate(1, $values));
 }
 /**
  * Instantiate and configure the node according to this definition
  *
  * @return Faker\Components\Engine\Common\Composite\CompositeInterface The node instance
  *
  * @throws InvalidDefinitionException When the definition is invalid
  */
 public function getNode()
 {
     if ($this->closure === null) {
         throw new EngineException('ClosureTypeDefinition must have a callable closure set before building the ClosureType');
     }
     $type = new ClosureType();
     $type->setGenerator($this->generator);
     $type->setUtilities($this->utilities);
     $type->setLocale($this->locale);
     $type->setClosure($this->closure);
     foreach ($this->attributes as $attribute => $value) {
         $type->setOption($attribute, $value);
     }
     return new TypeNode('ClosureType', $this->eventDispatcher, $type);
 }