| 361 | | |
| | 361 | /** |
| | 362 | * select u.id, u.status, p.phonenumber, upper(u.name) nameUpper, a.id, a.topic |
| | 363 | * from User u |
| | 364 | * join u.phonenumbers p |
| | 365 | * join u.articles a |
| | 366 | * = |
| | 367 | * select u.id, u.status, p.phonenumber, upper(u.name) as u__0, a.id, a.topic |
| | 368 | * from USERS u |
| | 369 | * inner join PHONENUMBERS p ON u.id = p.user_id |
| | 370 | * inner join ARTICLES a ON u.id = a.user_id |
| | 371 | * |
| | 372 | * @dataProvider hydrationModeProvider |
| | 373 | */ |
| | 374 | public function testNewHydrationMixedQueryMultipleFetchJoin($hydrationMode) |
| | 375 | { |
| | 376 | // Faked query components |
| | 377 | $queryComponents = array( |
| | 378 | 'u' => array( |
| | 379 | 'table' => $this->sharedFixture['connection']->getClassMetadata('CmsUser'), |
| | 380 | 'mapper' => $this->sharedFixture['connection']->getMapper('CmsUser'), |
| | 381 | 'parent' => null, |
| | 382 | 'relation' => null, |
| | 383 | 'map' => null, |
| | 384 | 'agg' => array('0' => 'nameUpper') |
| | 385 | ), |
| | 386 | 'p' => array( |
| | 387 | 'table' => $this->sharedFixture['connection']->getClassMetadata('CmsPhonenumber'), |
| | 388 | 'mapper' => $this->sharedFixture['connection']->getMapper('CmsPhonenumber'), |
| | 389 | 'parent' => 'u', |
| | 390 | 'relation' => $this->sharedFixture['connection']->getClassMetadata('CmsUser')->getRelation('phonenumbers'), |
| | 391 | 'map' => null |
| | 392 | ), |
| | 393 | 'a' => array( |
| | 394 | 'table' => $this->sharedFixture['connection']->getClassMetadata('CmsArticle'), |
| | 395 | 'mapper' => $this->sharedFixture['connection']->getMapper('CmsArticle'), |
| | 396 | 'parent' => 'u', |
| | 397 | 'relation' => $this->sharedFixture['connection']->getClassMetadata('CmsUser')->getRelation('articles'), |
| | 398 | 'map' => null |
| | 399 | ), |
| | 400 | ); |
| | 401 | |
| | 402 | // Faked table alias map |
| | 403 | $tableAliasMap = array( |
| | 404 | 'u' => 'u', |
| | 405 | 'p' => 'p', |
| | 406 | 'a' => 'a' |
| | 407 | ); |
| | 408 | |
| | 409 | // Faked result set |
| | 410 | $resultSet = array( |
| | 411 | //row1 |
| | 412 | array( |
| | 413 | 'u__id' => '1', |
| | 414 | 'u__status' => 'developer', |
| | 415 | 'u__0' => 'ROMANB', |
| | 416 | 'p__phonenumber' => '42', |
| | 417 | 'a__id' => '1', |
| | 418 | 'a__topic' => 'Getting things done!' |
| | 419 | ), |
| | 420 | array( |
| | 421 | 'u__id' => '1', |
| | 422 | 'u__status' => 'developer', |
| | 423 | 'u__0' => 'ROMANB', |
| | 424 | 'p__phonenumber' => '43', |
| | 425 | 'a__id' => '1', |
| | 426 | 'a__topic' => 'Getting things done!' |
| | 427 | ), |
| | 428 | array( |
| | 429 | 'u__id' => '1', |
| | 430 | 'u__status' => 'developer', |
| | 431 | 'u__0' => 'ROMANB', |
| | 432 | 'p__phonenumber' => '42', |
| | 433 | 'a__id' => '2', |
| | 434 | 'a__topic' => 'ZendCon' |
| | 435 | ), |
| | 436 | array( |
| | 437 | 'u__id' => '1', |
| | 438 | 'u__status' => 'developer', |
| | 439 | 'u__0' => 'ROMANB', |
| | 440 | 'p__phonenumber' => '43', |
| | 441 | 'a__id' => '2', |
| | 442 | 'a__topic' => 'ZendCon' |
| | 443 | ), |
| | 444 | array( |
| | 445 | 'u__id' => '2', |
| | 446 | 'u__status' => 'developer', |
| | 447 | 'u__0' => 'JWAGE', |
| | 448 | 'p__phonenumber' => '91', |
| | 449 | 'a__id' => '3', |
| | 450 | 'a__topic' => 'LINQ' |
| | 451 | ), |
| | 452 | array( |
| | 453 | 'u__id' => '2', |
| | 454 | 'u__status' => 'developer', |
| | 455 | 'u__0' => 'JWAGE', |
| | 456 | 'p__phonenumber' => '91', |
| | 457 | 'a__id' => '4', |
| | 458 | 'a__topic' => 'PHP6' |
| | 459 | ), |
| | 460 | ); |
| | 461 | |
| | 462 | $stmt = new Doctrine_HydratorMockStatement($resultSet); |
| | 463 | $hydrator = new Doctrine_HydratorNew(); |
| | 464 | $hydrator->setQueryComponents($queryComponents); |
| | 465 | |
| | 466 | $hydrator->setResultMixed(true); |
| | 467 | |
| | 468 | $result = $hydrator->hydrateResultSet($stmt, $tableAliasMap, $hydrationMode); |
| | 469 | if ($hydrationMode == Doctrine::HYDRATE_ARRAY) { |
| | 470 | //var_dump($result); |
| | 471 | } |
| | 472 | |
| | 473 | $this->assertEquals(2, count($result)); |
| | 474 | $this->assertTrue(is_array($result)); |
| | 475 | $this->assertTrue(is_array($result[0])); |
| | 476 | $this->assertTrue(is_array($result[1])); |
| | 477 | |
| | 478 | // first user => 2 phonenumbers, 2 articles |
| | 479 | $this->assertEquals(2, count($result[0][0]['phonenumbers'])); |
| | 480 | $this->assertEquals(2, count($result[0][0]['articles'])); |
| | 481 | $this->assertEquals('ROMANB', $result[0]['nameUpper']); |
| | 482 | // second user => 1 phonenumber, 2 articles |
| | 483 | $this->assertEquals(1, count($result[1][0]['phonenumbers'])); |
| | 484 | $this->assertEquals(2, count($result[1][0]['articles'])); |
| | 485 | $this->assertEquals('JWAGE', $result[1]['nameUpper']); |
| | 486 | |
| | 487 | $this->assertEquals(42, $result[0][0]['phonenumbers'][0]['phonenumber']); |
| | 488 | $this->assertEquals(43, $result[0][0]['phonenumbers'][1]['phonenumber']); |
| | 489 | $this->assertEquals(91, $result[1][0]['phonenumbers'][0]['phonenumber']); |
| | 490 | |
| | 491 | $this->assertEquals('Getting things done!', $result[0][0]['articles'][0]['topic']); |
| | 492 | $this->assertEquals('ZendCon', $result[0][0]['articles'][1]['topic']); |
| | 493 | $this->assertEquals('LINQ', $result[1][0]['articles'][0]['topic']); |
| | 494 | $this->assertEquals('PHP6', $result[1][0]['articles'][1]['topic']); |
| | 495 | |
| | 496 | if ($hydrationMode == Doctrine::HYDRATE_RECORD) { |
| | 497 | $this->assertTrue($result[0][0] instanceof Doctrine_Record); |
| | 498 | $this->assertTrue($result[0][0]['phonenumbers'] instanceof Doctrine_Collection); |
| | 499 | $this->assertTrue($result[0][0]['phonenumbers'][0] instanceof Doctrine_Record); |
| | 500 | $this->assertTrue($result[0][0]['phonenumbers'][1] instanceof Doctrine_Record); |
| | 501 | $this->assertTrue($result[0][0]['articles'] instanceof Doctrine_Collection); |
| | 502 | $this->assertTrue($result[0][0]['articles'][0] instanceof Doctrine_Record); |
| | 503 | $this->assertTrue($result[0][0]['articles'][1] instanceof Doctrine_Record); |
| | 504 | $this->assertTrue($result[1][0] instanceof Doctrine_Record); |
| | 505 | $this->assertTrue($result[1][0]['phonenumbers'] instanceof Doctrine_Collection); |
| | 506 | $this->assertTrue($result[1][0]['phonenumbers'][0] instanceof Doctrine_Record); |
| | 507 | $this->assertTrue($result[1][0]['articles'][0] instanceof Doctrine_Record); |
| | 508 | $this->assertTrue($result[1][0]['articles'][1] instanceof Doctrine_Record); |
| | 509 | } |
| | 510 | } |