BasicFunctionalTest.php 21.1 KB
Newer Older
1 2
<?php

3 4
namespace Doctrine\Tests\ORM\Functional;

5
use Doctrine\ORM\Tools\SchemaTool;
6 7
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
8
use Doctrine\Tests\Models\CMS\CmsAddress;
9
use Doctrine\Tests\Models\CMS\CmsGroup;
10

11
require_once __DIR__ . '/../../TestInit.php';
12

13
class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
14
{
15
    protected function setUp()
16
    {
17 18
        $this->useModelSet('cms');
        parent::setUp();
19
    }
20

21 22
    public function testBasicUnitsOfWorkWithOneToManyAssociation()
    {
23 24
        // Create
        $user = new CmsUser;
25 26 27
        $user->name = 'Roman';
        $user->username = 'romanb';
        $user->status = 'developer';
romanb's avatar
romanb committed
28
        $this->_em->persist($user);
29
       
romanb's avatar
romanb committed
30 31
        $this->_em->flush();
        
32
        $this->assertTrue(is_numeric($user->id));
33
        $this->assertTrue($this->_em->contains($user));
34 35

        // Read
36
        $user2 = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id);
37
        $this->assertTrue($user === $user2);
romanb's avatar
romanb committed
38

39
        // Add a phonenumber
romanb's avatar
romanb committed
40 41
        $ph = new CmsPhonenumber;
        $ph->phonenumber = "12345";
42
        $user->addPhonenumber($ph);
43 44 45
        $this->_em->flush();
        $this->assertTrue($this->_em->contains($ph));
        $this->assertTrue($this->_em->contains($user));
46
        //$this->assertTrue($user->phonenumbers instanceof \Doctrine\ORM\PersistentCollection);
romanb's avatar
romanb committed
47

48
        // Update name
49
        $user->name = 'guilherme';
50
        $this->_em->flush();
51 52
        $this->assertEquals('guilherme', $user->name);

53 54 55 56
        // Add another phonenumber
        $ph2 = new CmsPhonenumber;
        $ph2->phonenumber = "6789";
        $user->addPhonenumber($ph2);
57 58
        $this->_em->flush();
        $this->assertTrue($this->_em->contains($ph2));
59

60
        // Delete
romanb's avatar
romanb committed
61 62 63 64
        $this->_em->remove($user);
        $this->assertTrue($this->_em->getUnitOfWork()->isScheduledForDelete($user));
        $this->assertTrue($this->_em->getUnitOfWork()->isScheduledForDelete($ph));
        $this->assertTrue($this->_em->getUnitOfWork()->isScheduledForDelete($ph2));
65
        $this->_em->flush();
romanb's avatar
romanb committed
66 67 68
        $this->assertFalse($this->_em->getUnitOfWork()->isScheduledForDelete($user));
        $this->assertFalse($this->_em->getUnitOfWork()->isScheduledForDelete($ph));
        $this->assertFalse($this->_em->getUnitOfWork()->isScheduledForDelete($ph2));
69 70 71
        $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user));
        $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($ph));
        $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($ph2));
72
    }
romanb's avatar
romanb committed
73

74 75
    public function testOneToManyAssociationModification()
    {
76 77 78 79
        $user = new CmsUser;
        $user->name = 'Roman';
        $user->username = 'romanb';
        $user->status = 'developer';
80

81 82 83 84 85 86 87 88
        $ph1 = new CmsPhonenumber;
        $ph1->phonenumber = "0301234";
        $ph2 = new CmsPhonenumber;
        $ph2->phonenumber = "987654321";

        $user->addPhonenumber($ph1);
        $user->addPhonenumber($ph2);

romanb's avatar
romanb committed
89
        $this->_em->persist($user);
90 91
        $this->_em->flush();

92
        //$this->assertTrue($user->phonenumbers instanceof \Doctrine\ORM\PersistentCollection);
93 94 95 96

        // Remove the first element from the collection
        unset($user->phonenumbers[0]);
        $ph1->user = null; // owning side!
97

98 99 100 101 102 103 104 105 106 107 108 109
        $this->_em->flush();

        $this->assertEquals(1, count($user->phonenumbers));
        $this->assertNull($ph1->user);
    }

    public function testBasicOneToOne()
    {
        $user = new CmsUser;
        $user->name = 'Roman';
        $user->username = 'romanb';
        $user->status = 'developer';
110

111 112 113 114 115 116 117 118
        $address = new CmsAddress;
        $address->country = 'Germany';
        $address->city = 'Berlin';
        $address->zip = '12345';

        $user->address = $address; // inverse side
        $address->user = $user; // owning side!

romanb's avatar
romanb committed
119
        $this->_em->persist($user);
120
        $this->_em->flush();
121 122 123 124 125 126

        // Check that the foreign key has been set
        $userId = $this->_em->getConnection()->execute("SELECT user_id FROM cms_addresses WHERE id=?",
                array($address->id))->fetchColumn();
        $this->assertTrue(is_numeric($userId));
    }
127 128

    public function testBasicManyToMany()
129
    {        
130 131 132 133 134 135 136 137 138 139 140
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';

        $group = new CmsGroup;
        $group->name = 'Developers';

        $user->groups[] = $group;
        $group->users[] = $user;

romanb's avatar
romanb committed
141
        $this->_em->persist($user);
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

        $this->_em->flush();

        unset($group->users[0]); // inverse side
        unset($user->groups[0]); // owning side!

        $this->_em->flush();

        // Check that the link in the association table has been deleted
        $count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_users_groups",
                array())->fetchColumn();
        $this->assertEquals(0, $count);
    }

    public function testManyToManyCollectionClearing()
    {
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';

        for ($i=0; $i<10; ++$i) {
            $group = new CmsGroup;
            $group->name = 'Developers_' . $i;
            $user->groups[] = $group;
            $group->users[] = $user;
        }

romanb's avatar
romanb committed
170
        $this->_em->persist($user);
171

172
        $this->_em->flush();
romanb's avatar
romanb committed
173
        
174 175 176 177
        // Check that there are indeed 10 links in the association table
        $count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_users_groups",
                array())->fetchColumn();
        $this->assertEquals(10, $count);
178

romanb's avatar
romanb committed
179 180
        $user->groups->clear();
        //unset($user->groups);
181 182 183 184 185 186 187 188

        $this->_em->flush();

        // Check that the links in the association table have been deleted
        $count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_users_groups",
                array())->fetchColumn();
        $this->assertEquals(0, $count);
    }
romanb's avatar
romanb committed
189
    
190
    public function testOneToManyOrphanRemoval()
romanb's avatar
romanb committed
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
    {
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';

        for ($i=0; $i<3; ++$i) {
            $phone = new CmsPhonenumber;
            $phone->phonenumber = 100 + $i;
            $user->addPhonenumber($phone);
        }

        $this->_em->persist($user);

        $this->_em->flush();

        $user->getPhonenumbers()->remove(0);
208
        $this->assertEquals(2, count($user->getPhonenumbers()));
romanb's avatar
romanb committed
209 210 211

        $this->_em->flush();

212
        // Check that there are just 2 phonenumbers left
romanb's avatar
romanb committed
213 214 215
        $count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_phonenumbers",
                array())->fetchColumn();
        $this->assertEquals(2, $count); // only 2 remaining
216
    }
217 218 219 220 221 222 223

    public function testBasicQuery()
    {
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';
romanb's avatar
romanb committed
224
        $this->_em->persist($user);
225 226 227 228
        $this->_em->flush();

        $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u");

229
        $users = $query->getResult();
230

231
        $this->assertEquals(1, count($users));
232 233 234
        $this->assertEquals('Guilherme', $users[0]->name);
        $this->assertEquals('gblanco', $users[0]->username);
        $this->assertEquals('developer', $users[0]->status);
235 236
        //$this->assertNull($users[0]->phonenumbers);
        //$this->assertNull($users[0]->articles);
237

238
        $usersArray = $query->getArrayResult();
239 240 241 242 243 244 245 246 247 248 249 250 251 252

        $this->assertTrue(is_array($usersArray));
        $this->assertEquals(1, count($usersArray));
        $this->assertEquals('Guilherme', $usersArray[0]['name']);
        $this->assertEquals('gblanco', $usersArray[0]['username']);
        $this->assertEquals('developer', $usersArray[0]['status']);

        $usersScalar = $query->getScalarResult();

        $this->assertTrue(is_array($usersScalar));
        $this->assertEquals(1, count($usersScalar));
        $this->assertEquals('Guilherme', $usersScalar[0]['u_name']);
        $this->assertEquals('gblanco', $usersScalar[0]['u_username']);
        $this->assertEquals('developer', $usersScalar[0]['u_status']);
253 254
    }

255
    public function testBasicOneToManyInnerJoin()
256 257 258 259 260
    {
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';
romanb's avatar
romanb committed
261
        $this->_em->persist($user);
262 263 264 265
        $this->_em->flush();

        $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u join u.phonenumbers p");

266
        $users = $query->getResult();
267

268
        $this->assertEquals(0, count($users));
269 270
    }

271
    public function testBasicOneToManyLeftJoin()
272 273 274 275 276
    {
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';
romanb's avatar
romanb committed
277
        $this->_em->persist($user);
278 279 280 281
        $this->_em->flush();

        $query = $this->_em->createQuery("select u,p from Doctrine\Tests\Models\CMS\CmsUser u left join u.phonenumbers p");

282
        $users = $query->getResult();
283

284
        $this->assertEquals(1, count($users));
285 286 287 288 289
        $this->assertEquals('Guilherme', $users[0]->name);
        $this->assertEquals('gblanco', $users[0]->username);
        $this->assertEquals('developer', $users[0]->status);
        $this->assertTrue($users[0]->phonenumbers instanceof \Doctrine\ORM\PersistentCollection);
        $this->assertEquals(0, $users[0]->phonenumbers->count());
290
        //$this->assertNull($users[0]->articles);
291
    }
292 293 294 295 296 297 298 299 300 301 302 303 304

    public function testBasicManyToManyJoin()
    {
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';

        $group1 = new CmsGroup;
        $group1->setName('Doctrine Developers');

        $user->addGroup($group1);

romanb's avatar
romanb committed
305
        $this->_em->persist($user);
306 307 308 309 310 311 312 313
        
        $this->_em->flush();
        $this->_em->clear();

        $this->assertEquals(0, $this->_em->getUnitOfWork()->size());

        $query = $this->_em->createQuery("select u, g from Doctrine\Tests\Models\CMS\CmsUser u join u.groups g");

314
        $result = $query->getResult();
315 316 317 318 319 320 321
        
        $this->assertEquals(2, $this->_em->getUnitOfWork()->size());
        $this->assertTrue($result[0] instanceof CmsUser);
        $this->assertEquals('Guilherme', $result[0]->name);
        $this->assertEquals(1, $result[0]->getGroups()->count());
        $groups = $result[0]->getGroups();
        $this->assertEquals('Doctrine Developers', $groups[0]->getName());
322 323 324 325 326 327 328 329 330 331 332 333 334 335

        $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($result[0]));
        $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($groups[0]));

        $this->assertTrue($groups instanceof \Doctrine\ORM\PersistentCollection);
        $this->assertTrue($groups[0]->getUsers() instanceof \Doctrine\ORM\PersistentCollection);

        $groups[0]->getUsers()->clear();
        $groups->clear();

        $this->_em->flush();
        $this->_em->clear();

        $query = $this->_em->createQuery("select u, g from Doctrine\Tests\Models\CMS\CmsUser u inner join u.groups g");
336
        $this->assertEquals(0, count($query->getResult()));
337
    }
romanb's avatar
romanb committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
    
    public function testBasicRefresh()
    {
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';

        $this->_em->persist($user);
        $this->_em->flush();
        
        $user->status = 'mascot';
        
        $this->assertEquals('mascot', $user->status);
        $this->_em->refresh($user);
        $this->assertEquals('developer', $user->status);
    }
romanb's avatar
romanb committed
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
    
    public function testAddToCollectionDoesNotInitialize()
    {
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';

        for ($i=0; $i<3; ++$i) {
            $phone = new CmsPhonenumber;
            $phone->phonenumber = 100 + $i;
            $user->addPhonenumber($phone);
        }

        $this->_em->persist($user);
        $this->_em->flush();
        $this->_em->clear();
        
        $this->assertEquals(3, $user->getPhonenumbers()->count());
        
        $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username='gblanco'");

        $gblanco = $query->getSingleResult();
        
        $this->assertFalse($gblanco->getPhonenumbers()->isInitialized());
        
        $newPhone = new CmsPhonenumber;
romanb's avatar
romanb committed
382 383
        $newPhone->phonenumber = 555;
        $gblanco->addPhonenumber($newPhone);
romanb's avatar
romanb committed
384 385
        
        $this->assertFalse($gblanco->getPhonenumbers()->isInitialized());
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
        $this->_em->persist($gblanco);

        $this->_em->flush();
        $this->_em->clear();
        
        $query = $this->_em->createQuery("select u, p from Doctrine\Tests\Models\CMS\CmsUser u join u.phonenumbers p where u.username='gblanco'");
        $gblanco2 = $query->getSingleResult();
        $this->assertEquals(4, $gblanco2->getPhonenumbers()->count());
    }
    
    public function testInitializeCollectionWithNewObjectsRetainsNewObjects()
    {
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';

        for ($i=0; $i<3; ++$i) {
            $phone = new CmsPhonenumber;
            $phone->phonenumber = 100 + $i;
            $user->addPhonenumber($phone);
        }

        $this->_em->persist($user);
        $this->_em->flush();
        $this->_em->clear();
        
        $this->assertEquals(3, $user->getPhonenumbers()->count());
        
        $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username='gblanco'");

        $gblanco = $query->getSingleResult();
        
        $this->assertFalse($gblanco->getPhonenumbers()->isInitialized());
        
        $newPhone = new CmsPhonenumber;
        $newPhone->phonenumber = 555;
        $gblanco->addPhonenumber($newPhone);
        
        $this->assertFalse($gblanco->getPhonenumbers()->isInitialized());
        $this->assertEquals(4, $gblanco->getPhonenumbers()->count());
        $this->assertTrue($gblanco->getPhonenumbers()->isInitialized());
428

romanb's avatar
romanb committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
        $this->_em->flush();
        $this->_em->clear();
        
        $query = $this->_em->createQuery("select u, p from Doctrine\Tests\Models\CMS\CmsUser u join u.phonenumbers p where u.username='gblanco'");
        $gblanco2 = $query->getSingleResult();
        $this->assertEquals(4, $gblanco2->getPhonenumbers()->count());
    }
    
    public function testSetSetAssociationWithGetReference()
    {
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';        
        $this->_em->persist($user);
        
        $address = new CmsAddress;
        $address->country = 'Germany';
        $address->city = 'Berlin';
        $address->zip = '12345';
        $this->_em->persist($address);
        
        $this->_em->flush();
        $this->_em->detach($address);
        
        $this->assertFalse($this->_em->contains($address));
        $this->assertTrue($this->_em->contains($user));
        
        // Assume we only got the identifier of the address and now want to attach
        // that address to the user without actually loading it, using getReference().
        $addressRef = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsAddress', $address->getId());
        
461 462 463 464
        //$addressRef->getId();
        //\Doctrine\Common\Util\Debug::dump($addressRef);
        
        $user->setAddress($addressRef); // Ugh! Initializes address 'cause of $address->setUser($user)!
romanb's avatar
romanb committed
465 466 467 468 469 470 471
        
        $this->_em->flush();
        $this->_em->clear();
        
        // Check with a fresh load that the association is indeed there
        $query = $this->_em->createQuery("select u, a from Doctrine\Tests\Models\CMS\CmsUser u join u.address a where u.username='gblanco'");
        $gblanco = $query->getSingleResult();
472

romanb's avatar
romanb committed
473 474 475 476 477
        $this->assertTrue($gblanco instanceof CmsUser);
        $this->assertTrue($gblanco->getAddress() instanceof CmsAddress);
        $this->assertEquals('Berlin', $gblanco->getAddress()->getCity());
        
    }
romanb's avatar
romanb committed
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
    
    public function testOneToManyCascadeRemove()
    {
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';

        for ($i=0; $i<3; ++$i) {
            $phone = new CmsPhonenumber;
            $phone->phonenumber = 100 + $i;
            $user->addPhonenumber($phone);
        }

        $this->_em->persist($user);
        $this->_em->flush();
        $this->_em->clear();
        
        $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username='gblanco'");
        $gblanco = $query->getSingleResult();
        
        $this->_em->remove($gblanco);
        $this->_em->flush();
        
        $this->_em->clear();
        
        $this->assertEquals(0, $this->_em->createQuery(
                "select count(p.phonenumber) from Doctrine\Tests\Models\CMS\CmsPhonenumber p")
                ->getSingleScalarResult());
        
        $this->assertEquals(0, $this->_em->createQuery(
                "select count(u.id) from Doctrine\Tests\Models\CMS\CmsUser u")
                ->getSingleScalarResult());
    }
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532

    public function testTextColumnSaveAndRetrieve()
    {
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';

        $this->_em->persist($user);

        $article = new \Doctrine\Tests\Models\CMS\CmsArticle();
        $article->text = "Lorem ipsum dolor sunt.";
        $article->topic = "A Test Article!";
        $article->setAuthor($user);

        $this->_em->persist($article);
        $this->_em->flush();
        $articleId = $article->id;

        $this->_em->clear();

533 534 535 536 537 538 539 540 541 542 543 544
        $articleNew = $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $articleId);
        $this->assertEquals("Lorem ipsum dolor sunt.", $articleNew->text);
        
        $this->assertNotSame($article, $articleNew);

        $articleNew->text = "Lorem ipsum dolor sunt. And stuff!";

        $this->_em->flush();
        $this->_em->clear();

        $articleNew = $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $articleId);
        $this->assertEquals("Lorem ipsum dolor sunt. And stuff!", $articleNew->text);
545
    }
546
    
romanb's avatar
romanb committed
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
    public function testFlushDoesNotIssueUnnecessaryUpdates()
    {
        
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';
        
        $address = new CmsAddress;
        $address->country = 'Germany';
        $address->city = 'Berlin';
        $address->zip = '12345';
        
        $address->user = $user;
        $user->address = $address;
        
563 564 565 566 567 568
        $article = new \Doctrine\Tests\Models\CMS\CmsArticle();
        $article->text = "Lorem ipsum dolor sunt.";
        $article->topic = "A Test Article!";
        $article->setAuthor($user);
        
        $this->_em->persist($article);
romanb's avatar
romanb committed
569 570
        $this->_em->persist($user);
        
571 572
        //$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
        
romanb's avatar
romanb committed
573 574
        $this->_em->flush();
        $this->_em->clear();
575 576
        
        $query = $this->_em->createQuery('select u,a,ad from Doctrine\Tests\Models\CMS\CmsUser u join u.articles a join u.address ad');
romanb's avatar
romanb committed
577
        $user2 = $query->getSingleResult();
578 579 580

        $this->assertEquals(1, count($user2->articles));
        $this->assertTrue($user2->address instanceof CmsAddress);
romanb's avatar
romanb committed
581 582 583 584 585 586 587 588 589 590 591
        
        $oldLogger = $this->_em->getConnection()->getConfiguration()->getSqlLogger();
        $debugStack = new \Doctrine\DBAL\Logging\DebugStack;
        $this->_em->getConnection()->getConfiguration()->setSqlLogger($debugStack);
        
        $this->_em->flush();
        $this->assertEquals(0, count($debugStack->queries));
        
        $this->_em->getConnection()->getConfiguration()->setSqlLogger($oldLogger);
    }
    
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
    //DRAFT OF EXPECTED/DESIRED BEHAVIOR
    /*public function testPersistentCollectionContainsDoesNeverInitialize()
    {
        $user = new CmsUser;
        $user->name = 'Guilherme';
        $user->username = 'gblanco';
        $user->status = 'developer';
        
        $group = new CmsGroup;
        $group->name = 'Developers';
        
        $user->addGroup($group);
        
        $this->_em->persist($user);
        $this->_em->flush();
        $this->_em->clear();
        
        $group = $this->_em->find(get_class($group), $group->getId());
        
        
        
        $user2 = new CmsUser;
        $user2->id = $user->getId();
        $this->assertFalse($group->getUsers()->contains($user2));
        $this->assertFalse($group->getUsers()->isInitialized());
        
        $user2 = $this->_em->getReference(get_class($user), $user->getId());
        $this->assertTrue($group->getUsers()->contains($user2));
        $this->assertFalse($group->getUsers()->isInitialized());
        
    }
    */
624
}