forked from doctrine/orm
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PersistenCollections had a problem with serializing; they need to be initialized beforehands.
- Loading branch information
Showing
3 changed files
with
155 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
namespace Doctrine\Tests\ORM\Functional; | ||
|
||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
use Doctrine\Tests\Models\CMS\CmsUser; | ||
use Doctrine\Tests\Models\CMS\CmsGroup; | ||
use Doctrine\Tests\Models\CMS\CmsPhonenumber; | ||
use Doctrine\Tests\Models\CMS\CmsAddress; | ||
use Doctrine\ORM\UnitOfWork; | ||
|
||
require_once __DIR__ . '/../../../TestInit.php'; | ||
/** | ||
* ----------------- !! NOTE !! -------------------- | ||
* To reproduce the manyToMany-Bug it's necessary | ||
* to cascade "merge" on cmUser::groups | ||
* ------------------------------------------------- | ||
* | ||
* @PHP-Version 5.3.2 | ||
* @PHPUnit-Version 3.4.11 | ||
* | ||
* @author markus | ||
*/ | ||
class DetachedPartiallyLoadedEntityTest extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp() { | ||
$this->useModelSet('cms'); | ||
parent::setUp(); | ||
} | ||
|
||
public function testCreateUser() | ||
{ | ||
### Create User | ||
$user = $this->createAndPersistUser(); | ||
$this->_em->flush(); | ||
|
||
$this->assertTrue($this->_em->contains($user)); | ||
$this->_em->clear(); | ||
$this->assertFalse($this->_em->contains($user)); | ||
|
||
unset($user); | ||
|
||
### Reload User from DB *without* any associations | ||
$userReloaded = $this->loadUserFromEntityManager(); | ||
|
||
$this->assertTrue($this->_em->contains($userReloaded)); | ||
$this->_em->clear(); | ||
$this->assertFalse($this->_em->contains($userReloaded)); | ||
|
||
// freeze and unfreeze | ||
$string = serialize($userReloaded); | ||
unset($userReloaded); | ||
$userClone = unserialize($string); | ||
$this->assertType('Doctrine\Tests\Models\CMS\CmsUser', $userClone); | ||
|
||
$this->assertEquals(4, count($userClone->getPhonenumbers())); | ||
$this->assertEquals(2, count($userClone->getGroups())); | ||
|
||
### Merge back and flush | ||
$userClone = $this->_em->merge($userClone); | ||
|
||
/* | ||
* Back in managed world I would expect to have my phonenumbers back but they aren't! | ||
* Remember I didn't touch (and propably didn't need) them at all while in detached mode. | ||
*/ | ||
$this->assertEquals(4, count($userClone->getPhonenumbers()), 'Phonenumbers are not available anymore'); | ||
|
||
/* | ||
* This works fine as long as cmUser::groups doesn't cascade "merge" | ||
*/ | ||
$this->assertEquals(2, count($userClone->getGroups())); | ||
|
||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
$this->assertFalse($this->_em->contains($userClone)); | ||
|
||
### Reload user from DB | ||
$userFromEntityManager = $this->loadUserFromEntityManager(); | ||
|
||
/* | ||
* Strange: Now the phonenumbers are back again | ||
*/ | ||
$this->assertEquals(4, count($userFromEntityManager->getPhonenumbers())); | ||
|
||
/* | ||
* This works fine as long as cmUser::groups doesn't cascade "merge" | ||
* Otherwise group memberships are physically deleted now! | ||
*/ | ||
$this->assertEquals(2, count($userClone->getGroups())); | ||
} | ||
|
||
protected function createAndPersistUser() | ||
{ | ||
$user = new CmsUser(); | ||
$user->name = 'Luka'; | ||
$user->username = 'lukacho'; | ||
$user->status = 'developer'; | ||
|
||
foreach(array(1111,2222,3333,4444) as $number) { | ||
$phone = new CmsPhonenumber; | ||
$phone->phonenumber = $number; | ||
$user->addPhonenumber($phone); | ||
} | ||
|
||
foreach(array('Moshers', 'Headbangers') as $groupName) { | ||
$group = new CmsGroup; | ||
$group->setName($groupName); | ||
$user->addGroup($group); | ||
} | ||
|
||
$this->_em->persist($user); | ||
|
||
return $user; | ||
} | ||
|
||
/** | ||
* @return Doctrine\Tests\Models\CMS\CmsUser | ||
*/ | ||
protected function loadUserFromEntityManager() | ||
{ | ||
return $this->_em | ||
->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name like :name') | ||
->setParameter('name', 'Luka') | ||
->getSingleResult(); | ||
} | ||
|
||
} |
6c185a2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the bugfix? I don't see a relevant change...