DDC748Test.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Tests\Models\CMS\CmsUser;
  5. use Doctrine\Tests\Models\CMS\CmsArticle;
  6. use Doctrine\Tests\Models\CMS\CmsAddress;
  7. require_once __DIR__ . '/../../../TestInit.php';
  8. class DDC748Test extends \Doctrine\Tests\OrmFunctionalTestCase
  9. {
  10. protected function setUp()
  11. {
  12. $this->useModelSet('cms');
  13. parent::setUp();
  14. }
  15. public function testRefreshWithManyToOne()
  16. {
  17. $user = new CmsUser();
  18. $user->name = "beberlei";
  19. $user->status = "active";
  20. $user->username = "beberlei";
  21. $article = new CmsArticle();
  22. $article->setAuthor($user);
  23. $article->text = "foo";
  24. $article->topic = "bar";
  25. $this->_em->persist($user);
  26. $this->_em->persist($article);
  27. $this->_em->flush();
  28. $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $user->articles);
  29. $this->_em->refresh($article);
  30. $this->assertTrue($article !== $user->articles, "The article should not be replaced on the inverse side of the relation.");
  31. $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $user->articles);
  32. }
  33. public function testRefreshOneToOne()
  34. {
  35. $user = new CmsUser();
  36. $user->name = "beberlei";
  37. $user->status = "active";
  38. $user->username = "beberlei";
  39. $address = new CmsAddress();
  40. $address->city = "Bonn";
  41. $address->country = "Germany";
  42. $address->street = "A street";
  43. $address->zip = 12345;
  44. $address->setUser($user);
  45. $this->_em->persist($user);
  46. $this->_em->persist($address);
  47. $this->_em->flush();
  48. $this->_em->refresh($address);
  49. $this->assertSame($user, $address->user);
  50. $this->assertSame($user->address, $address);
  51. }
  52. }