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'); $event = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $parent = $this->getMock('Faker\\Components\\Engine\\Common\\Composite\\CompositeInterface'); $childA = $this->getMockBuilder('Faker\\Components\\Engine\\Common\\Composite\\GenericNode')->disableOriginalConstructor()->getMock(); $childA->expects($this->once())->method('generate')->with($this->equalTo(5), $this->equalTo(array('row1' => 6)))->will($this->returnValue('a generated string')); $childB = $this->getMockBuilder('Faker\\Components\\Engine\\Common\\Composite\\GenericNode')->disableOriginalConstructor()->getMock(); $id = 'testnode'; $internal = $this->getMock('\\Faker\\Components\\Engine\\Common\\Type\\TypeInterface'); $internal->expects($this->once())->method('generate')->with($this->equalTo(5), $this->equalTo(array('row1' => 6)))->will($this->returnValue(1)); $type = new SelectorNode($id, $event, $internal); $type->setParent($parent); $type->addChild($childA); $type->addChild($childB); $values = array('row1' => 6); $this->assertEquals('a generated string', $type->generate(5, $values)); }
/** * 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 SwapSelector(); $type->setGenerator($this->generator); $type->setUtilities($this->utilities); $type->setLocale($this->locale); foreach ($this->attributes as $attribute => $value) { $type->setOption($attribute, $value); } # register position managers foreach ($this->positionManagers as $mgr) { $type->registerSwap($mgr); } $node = new SelectorNode('selectorNode', $this->eventDispatcher, $type); # register children foreach ($this->children as $aNode) { $node->addChild($aNode); } # return the composite generator selectorNode return $node; }