DDC812Test.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\Tests\Models\CMS\CmsArticle;
  4. use Doctrine\Tests\Models\CMS\CmsComment;
  5. require_once __DIR__ . '/../../../TestInit.php';
  6. class DDC812Test extends \Doctrine\Tests\OrmFunctionalTestCase
  7. {
  8. protected function setUp()
  9. {
  10. $this->useModelSet('cms');
  11. parent::setUp();
  12. }
  13. /**
  14. * @group DDC-812
  15. */
  16. public function testFetchJoinInitializesPreviouslyUninitializedCollectionOfManagedEntity()
  17. {
  18. //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
  19. $article = new CmsArticle;
  20. $article->topic = "hello";
  21. $article->text = "talk talk talk";
  22. $comment = new CmsComment;
  23. $comment->topic = "good!";
  24. $comment->text = "stuff!";
  25. $comment->article = $article;
  26. $this->_em->persist($article);
  27. $this->_em->persist($comment);
  28. $this->_em->flush();
  29. $this->_em->clear();
  30. $article2 = $this->_em->find(get_class($article), $article->id);
  31. $article2Again = $this->_em->createQuery(
  32. "select a, c from Doctrine\Tests\Models\CMS\CmsArticle a join a.comments c where a.id = ?1")
  33. ->setParameter(1, $article->id)
  34. ->getSingleResult();
  35. $this->assertTrue($article2Again === $article2);
  36. $this->assertTrue($article2Again->comments->isInitialized());
  37. }
  38. }