/**
  *  Fetch the node managed by this definition
  *
  *  @access public
  *  @return Faker\Components\Engine\Common\Composite\CompositeInterface the new node
  */
 public function getNode()
 {
     # construct the selector type
     $type = new PickSelector();
     $type->setGenerator($this->generator);
     $type->setUtilities($this->utilities);
     $type->setLocale($this->locale);
     foreach ($this->attributes as $attribute => $value) {
         $type->setOption($attribute, $value);
     }
     # return the composite generator selectorNode
     return new SelectorNode('selectorNode', $this->eventDispatcher, $type);
 }
Exemplo n.º 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');
     $type = new PickSelector();
     $type->setGenerator($generator);
     $type->setLocale($locale);
     $type->setUtilities($utilities);
     $type->setOption('probability', 0.5);
     $type->validate();
     $generator->expects($this->at(0))->method('generate')->with($this->equalTo(0), $this->equalTo(100))->will($this->returnValue(80));
     $generator->expects($this->at(1))->method('generate')->with($this->equalTo(0), $this->equalTo(100))->will($this->returnValue(40));
     $generator->expects($this->at(2))->method('generate')->with($this->equalTo(0), $this->equalTo(100))->will($this->returnValue(50));
     $generator->expects($this->at(3))->method('generate')->with($this->equalTo(0), $this->equalTo(100))->will($this->returnValue(80));
     $generator->expects($this->at(4))->method('generate')->with($this->equalTo(0), $this->equalTo(100))->will($this->returnValue(100));
     $values = array();
     $this->assertEquals(1, $type->generate(1, $values));
     $this->assertEquals(2, $type->generate(1, $values));
     $this->assertEquals(2, $type->generate(1, $values));
     $this->assertEquals(1, $type->generate(1, $values));
     $this->assertEquals(1, $type->generate(1, $values));
 }