Ejemplo n.º 1
0
 public function testDefine()
 {
     $producer = $this->getMockBuilder('Fabrika\\ProducerAbstract')->getMockForAbstractClass();
     /**
      * @var ProducerAbstract $producer
      */
     $producer->define('user')->addField('id', new AutoIncrement())->addField('username', new StringSequence('username{n}'));
     $this->assertTrue($producer->hasDefinition('user'));
     $this->assertInstanceOf('Fabrika\\Definition', $producer->getDefinition('user'));
     $this->assertTrue($producer->getDefinition('user')->hasField('username'));
     $definition = new Definition('book');
     $definition->addField('id', new AutoIncrement())->addField('title', new StringSequence('title{n}'));
     $producer = $this->getMockBuilder('Fabrika\\ProducerAbstract')->getMockForAbstractClass();
     /**
      * @var ProducerAbstract $producer
      */
     $producer->define($definition);
     $this->assertTrue($producer->hasDefinition('book'));
     $this->assertInstanceOf('Fabrika\\Definition', $producer->getDefinition('book'));
     $this->assertTrue($producer->getDefinition('book')->hasField('title'));
 }
Ejemplo n.º 2
0
 public function testInvokeOnIncrementCounters()
 {
     $definition = new Definition('user');
     $definition->addField('id', new AutoIncrement())->addField('username', new StringSequence('username{n}'));
     $definition->getField('id')->getGenerator()->generate();
     $id = $definition->getField('id')->getGenerator()->generate();
     $this->assertEquals(2, $id);
     $definition->invokeOnIncrementCounters(10);
     $id = $definition->getField('id')->getGenerator()->generate();
     $this->assertEquals(13, $id);
 }