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