/** * 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 AlternateSelector(); $type->setGenerator($this->generator); $type->setUtilities($this->utilities); $type->setLocale($this->locale); $type->setOption('set', count($this->children())); foreach ($this->attributes as $attribute => $value) { $type->setOption($attribute, $value); } # return the composite generator selectorNode return new SelectorNode('selectorNode', $this->eventDispatcher, $type); }
public function testGenerate() { $values = array(); $utilities = $this->getMockBuilder('Faker\\Components\\Engine\\Common\\Utilities')->disableOriginalConstructor()->getMock(); $generator = $this->getMock('\\PHPStats\\Generator\\GeneratorInterface'); $locale = $this->getMock('\\Faker\\Locale\\LocaleInterface'); $type = new AlternateSelector(); $type->setGenerator($generator); $type->setLocale($locale); $type->setUtilities($utilities); $type->setOption('set', 5); $type->setOption('step', 1); $this->assertTrue($type->validate()); $this->assertEquals(1, $type->generate(0, $values)); $this->assertEquals(2, $type->generate(0, $values)); $this->assertEquals(3, $type->generate(0, $values)); $this->assertEquals(4, $type->generate(0, $values)); $this->assertEquals(5, $type->generate(0, $values)); $type->setOption('set', 3); $type->setOption('step', 3); $this->assertTrue($type->validate()); $this->assertEquals(1, $type->generate(0, $values)); $this->assertEquals(1, $type->generate(0, $values)); $this->assertEquals(1, $type->generate(0, $values)); $this->assertEquals(2, $type->generate(0, $values)); $this->assertEquals(2, $type->generate(0, $values)); $this->assertEquals(2, $type->generate(0, $values)); $this->assertEquals(3, $type->generate(0, $values)); $this->assertEquals(3, $type->generate(0, $values)); $this->assertEquals(3, $type->generate(0, $values)); # loop ok $this->assertEquals(1, $type->generate(0, $values)); $this->assertEquals(1, $type->generate(0, $values)); $this->assertEquals(1, $type->generate(0, $values)); $this->assertEquals(2, $type->generate(0, $values)); $this->assertEquals(2, $type->generate(0, $values)); $this->assertEquals(2, $type->generate(0, $values)); $this->assertEquals(3, $type->generate(0, $values)); $this->assertEquals(3, $type->generate(0, $values)); $this->assertEquals(3, $type->generate(0, $values)); }