/**
  * {@inheritdoc}
  */
 public function write(array $items)
 {
     foreach ($items as $item) {
         if ($this instanceof CleanUpInterface) {
             $this->cleanUp($item);
         }
         $this->insertFromSelectQueryExecutor->execute($this->entityName, $this->fields, $this->getQueryBuilder($item));
     }
 }
 public function testWrite()
 {
     /** @var QueryBuilder|\PHPUnit_Framework_MockObject_MockObject $firstQueryBuilder */
     $firstQueryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     /** @var EntityManager|\PHPUnit_Framework_MockObject_MockObject $em */
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     // Used for showing difference between first and second QueryBuilders
     /** @var QueryBuilder $secondQueryBuilder */
     $secondQueryBuilder = new QueryBuilder($em);
     $items = [[AbstractNativeQueryWriter::QUERY_BUILDER => $firstQueryBuilder], [AbstractNativeQueryWriter::QUERY_BUILDER => $secondQueryBuilder]];
     $entityName = 'Bundle:EntityName';
     $fields = ['name', 'description'];
     $this->writer->setEntityName($entityName);
     $this->writer->setFields($fields);
     $this->queryExecutor->expects($this->at(0))->method('execute')->with($entityName, $fields, $firstQueryBuilder);
     $this->queryExecutor->expects($this->at(1))->method('execute')->with($entityName, $fields, $secondQueryBuilder);
     $this->writer->write($items);
 }
 public function testExecute()
 {
     $decimalValue = 12345678.29;
     $group = $this->registry->getManagerForClass('OroUserBundle:Group')->getRepository('OroUserBundle:Group')->findOneBy(['name' => 'Administrators']);
     /** @var QueryBuilder $queryBuilder */
     $queryBuilder = $this->registry->getManagerForClass('OroUserBundle:User')->getRepository('OroUserBundle:User')->createQueryBuilder('u')->select('u.email')->addSelect('u.id')->addSelect("{$decimalValue}")->addSelect('(TRUE)')->addSelect('u.createdAt')->addSelect('u.id')->addSelect('IDENTITY(u.organization)')->innerJoin('u.groups', 'g')->where('u.createdAt <= :datetime')->andWhere('g = :group')->setParameter('datetime', new \DateTime())->setParameter('group', $group);
     $this->queryExecutor->execute('OroTestFrameworkBundle:Item', ['stringValue', 'integerValue', 'decimalValue', 'booleanValue', 'datetimeValue', 'owner', 'organization'], $queryBuilder);
     /** @var User[] $result */
     $users = $this->registry->getManagerForClass('OroUserBundle:User')->getRepository('OroUserBundle:User')->findAll();
     /** @var Item[] $items */
     $items = $this->registry->getManagerForClass('OroTestFrameworkBundle:Item')->getRepository('OroTestFrameworkBundle:Item')->findAll();
     $this->assertNotEmpty($items);
     $this->assertCount(count($users), $items);
     foreach ($users as $index => $user) {
         $item = $items[$index];
         $this->assertEquals($user->getEmail(), $item->stringValue);
         $this->assertEquals($user->getId(), $item->integerValue);
         $this->assertEquals($decimalValue, $item->decimalValue);
         $this->assertTrue($item->booleanValue);
         $this->assertEquals($user->getCreatedAt(), $item->datetimeValue);
         $this->assertSame($user, $item->owner);
         $this->assertSame($user->getOrganization(), $item->organization);
     }
 }