/**
  * Times for comparison:
  *
  * [romanb: 10000 rows => 3.0 seconds]
  *
  * MAXIMUM TIME: 4 seconds
  */
 public function testNewHydrationMixedQueryFetchJoinArrayHydrationPerformance()
 {
     $rsm = new ResultSetMapping();
     $rsm->addEntityResult('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'u');
     $rsm->addJoinedEntityResult('Doctrine\\Tests\\Models\\CMS\\CmsPhonenumber', 'p', 'u', $this->_em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser')->getAssociationMapping('phonenumbers'));
     $rsm->addFieldResult('u', 'u__id', 'id');
     $rsm->addFieldResult('u', 'u__status', 'status');
     $rsm->addFieldResult('u', 'u__username', 'username');
     $rsm->addFieldResult('u', 'u__name', 'name');
     $rsm->addScalarResult('sclr0', 'nameUpper');
     $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber');
     // Faked result set
     $resultSet = array(array('u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', 'sclr0' => 'ROMANB', 'p__phonenumber' => '42'), array('u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', 'sclr0' => 'ROMANB', 'p__phonenumber' => '43'), array('u__id' => '2', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', 'sclr0' => 'JWAGE', 'p__phonenumber' => '91'));
     for ($i = 4; $i < 10000; ++$i) {
         $resultSet[] = array('u__id' => $i, 'u__status' => 'developer', 'u__username' => 'jwage', 'u__name' => 'Jonathan', 'sclr0' => 'JWAGE' . $i, 'p__phonenumber' => '91');
     }
     $stmt = new HydratorMockStatement($resultSet);
     $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
     $this->setMaxRunningTime(4);
     $result = $hydrator->hydrateAll($stmt, $rsm);
 }
Example #2
0
 public function testResultIteration()
 {
     $rsm = new ResultSetMapping();
     $rsm->addEntityResult('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'u');
     $rsm->addFieldResult('u', 'u__id', 'id');
     $rsm->addFieldResult('u', 'u__name', 'name');
     // Faked result set
     $resultSet = array(array('u__id' => '1', 'u__name' => 'romanb'), array('u__id' => '2', 'u__name' => 'jwage'));
     $stmt = new HydratorMockStatement($resultSet);
     $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
     $iterableResult = $hydrator->iterate($stmt, $rsm);
     $rowNum = 0;
     while (($row = $iterableResult->next()) !== false) {
         $this->assertEquals(1, count($row));
         $this->assertTrue(is_array($row[0]));
         if ($rowNum == 0) {
             $this->assertEquals(1, $row[0]['id']);
             $this->assertEquals('romanb', $row[0]['name']);
         } else {
             if ($rowNum == 1) {
                 $this->assertEquals(2, $row[0]['id']);
                 $this->assertEquals('jwage', $row[0]['name']);
             }
         }
         ++$rowNum;
     }
 }
 /**
  * Times for comparison:
  *
  * [romanb: 10000 rows => 1.4 seconds]
  *
  * MAXIMUM TIME: 3 seconds
  */
 public function testMixedQueryFetchJoinArrayHydrationPerformance10000Rows()
 {
     $rsm = new ResultSetMapping();
     $rsm->addEntityResult('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'u');
     $rsm->addJoinedEntityResult('Doctrine\\Tests\\Models\\CMS\\CmsPhonenumber', 'p', 'u', 'phonenumbers');
     $rsm->addFieldResult('u', 'u__id', 'id');
     $rsm->addFieldResult('u', 'u__status', 'status');
     $rsm->addFieldResult('u', 'u__username', 'username');
     $rsm->addFieldResult('u', 'u__name', 'name');
     $rsm->addScalarResult('sclr0', 'nameUpper');
     $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber');
     // Faked result set
     $resultSet = array(array('u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', 'sclr0' => 'ROMANB', 'p__phonenumber' => '42'), array('u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', 'sclr0' => 'ROMANB', 'p__phonenumber' => '43'), array('u__id' => '2', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', 'sclr0' => 'JWAGE', 'p__phonenumber' => '91'));
     for ($i = 4; $i < 10000; ++$i) {
         $resultSet[] = array('u__id' => $i, 'u__status' => 'developer', 'u__username' => 'jwage', 'u__name' => 'Jonathan', 'sclr0' => 'JWAGE' . $i, 'p__phonenumber' => '91');
     }
     $stmt = new HydratorMockStatement($resultSet);
     $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
     $this->setMaxRunningTime(3);
     $s = microtime(true);
     $result = $hydrator->hydrateAll($stmt, $rsm);
     $e = microtime(true);
     echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
 }
Example #4
0
 /**
  * SELECT PARTIAL u.{id, status}, UPPER(u.name) AS nameUpper
  *   FROM Doctrine\Tests\Models\CMS\CmsUser u
  *        INDEX BY u.id
  *
  * @group DDC-1385
  * @dataProvider provideDataForUserEntityResult
  */
 public function testIndexByAndMixedResult($userEntityKey)
 {
     $rsm = new ResultSetMapping();
     $rsm->addEntityResult('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'u', $userEntityKey ?: null);
     $rsm->addFieldResult('u', 'u__id', 'id');
     $rsm->addFieldResult('u', 'u__status', 'status');
     $rsm->addScalarResult('sclr0', 'nameUpper');
     $rsm->addIndexBy('u', 'id');
     // Faked result set
     $resultSet = array(array('u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB'), array('u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE'));
     $stmt = new HydratorMockStatement($resultSet);
     $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
     $result = $hydrator->hydrateAll($stmt, $rsm);
     $this->assertEquals(2, count($result));
     $this->assertTrue(isset($result[1]));
     $this->assertEquals(1, $result[1][$userEntityKey]['id']);
     $this->assertTrue(isset($result[2]));
     $this->assertEquals(2, $result[2][$userEntityKey]['id']);
 }
 /**
  * @group DDC-1358
  */
 public function testMissingIdForRootEntity()
 {
     $rsm = new ResultSetMapping();
     $rsm->addEntityResult('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'u');
     $rsm->addFieldResult('u', 'u__id', 'id');
     $rsm->addFieldResult('u', 'u__status', 'status');
     $rsm->addScalarResult('sclr0', 'nameUpper');
     // Faked result set
     $resultSet = array(array('u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB'), array('u__id' => null, 'u__status' => null, 'sclr0' => 'ROMANB'), array('u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE'), array('u__id' => null, 'u__status' => null, 'sclr0' => 'JWAGE'));
     $stmt = new HydratorMockStatement($resultSet);
     $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
     $result = $hydrator->hydrateAll($stmt, $rsm);
     $this->assertEquals(4, count($result), "Should hydrate four results.");
     $this->assertEquals('ROMANB', $result[0]['nameUpper']);
     $this->assertEquals('ROMANB', $result[1]['nameUpper']);
     $this->assertEquals('JWAGE', $result[2]['nameUpper']);
     $this->assertEquals('JWAGE', $result[3]['nameUpper']);
     $this->assertEquals(array('id' => 1, 'status' => 'developer'), $result[0][0]);
     $this->assertNull($result[1][0]);
     $this->assertEquals(array('id' => 2, 'status' => 'developer'), $result[2][0]);
     $this->assertNull($result[3][0]);
 }
 /**
  * @group DDC-644
  */
 public function testSkipUnknownColumns()
 {
     $rsm = new ResultSetMapping();
     $rsm->addEntityResult('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'u');
     $rsm->addFieldResult('u', 'u__id', 'id');
     $rsm->addFieldResult('u', 'u__name', 'name');
     // Faked result set
     $resultSet = array(array('u__id' => '1', 'u__name' => 'romanb', 'foo' => 'bar'));
     $stmt = new HydratorMockStatement($resultSet);
     $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
     $result = $hydrator->hydrateAll($stmt, $rsm);
     $this->assertEquals(1, count($result));
 }