/** * 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 AutoIncrement(); $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('AutoIncrement', $this->eventDispatcher, $type); }
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 AutoIncrement(); $type->setGenerator($generator); $type->setLocale($locale); $type->setUtilities($utilities); # test with start > 0 $type->setOption('start', 1); $type->setOption('increment', 4); $type->validate(); $values = array(); $this->assertEquals(1, $type->generate(1, $values)); $this->assertEquals(5, $type->generate(2, $values)); $this->assertEquals(9, $type->generate(3, $values)); # test with start at 0 $type = new AutoIncrement(); $type->setGenerator($generator); $type->setLocale($locale); $type->setUtilities($utilities); $type->setOption('start', 0); $type->setOption('increment', 4); $type->validate(); $values = array(); $this->assertEquals(0, $type->generate(1, $values)); $this->assertEquals(4, $type->generate(2, $values)); $this->assertEquals(8, $type->generate(3, $values)); # test with non int increment $type = new AutoIncrement(); $type->setGenerator($generator); $type->setLocale($locale); $type->setUtilities($utilities); $type->setOption('start', 0); $type->setOption('increment', 0.5); $type->validate(); $values = array(); $this->assertEquals(0, $type->generate(1, $values)); $this->assertEquals(0.5, $type->generate(2, $values)); $this->assertEquals(1, $type->generate(3, $values)); }