1
0
mirror of synced 2025-02-03 13:59:27 +03:00

79 lines
1.8 KiB
PHP
Raw Normal View History

2012-06-11 17:41:00 -03:00
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\Models\Quote\User;
use Doctrine\Tests\Models\Quote\Address;
/**
* @group DDC-1845
* @group DDC-142
*/
class DDC142Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp() : void
2012-06-11 17:41:00 -03:00
{
$this->useModelSet('quote');
2012-06-11 17:41:00 -03:00
parent::setUp();
2012-06-11 17:41:00 -03:00
}
2013-03-11 00:08:58 +00:00
public function testCreateRetrieveUpdateDelete()
2012-06-11 17:41:00 -03:00
{
$user = new User;
$user->name = 'FabioBatSilva';
$this->_em->persist($user);
$address = new Address;
$address->zip = '12345';
$this->_em->persist($address);
$this->_em->flush();
$addressRef = $this->_em->getReference(Address::class, $address->getId());
2012-06-11 17:41:00 -03:00
$user->setAddress($addressRef);
$this->_em->flush();
$this->_em->clear();
2012-06-11 18:21:22 -03:00
$id = $user->id;
$this->assertNotNull($id);
$user = $this->_em->find(User::class, $id);
2012-06-11 18:21:22 -03:00
$address = $user->getAddress();
$this->assertInstanceOf(User::class, $user);
$this->assertInstanceOf(Address::class, $user->getAddress());
2012-06-11 17:41:00 -03:00
2012-06-11 18:21:22 -03:00
$this->assertEquals('FabioBatSilva', $user->name);
$this->assertEquals('12345', $address->zip);
$user->name = 'FabioBatSilva1';
$user->address = null;
$this->_em->persist($user);
$this->_em->remove($address);
$this->_em->flush();
$this->_em->clear();
$user = $this->_em->find(User::class, $id);
$this->assertInstanceOf(User::class, $user);
2012-06-11 18:21:22 -03:00
$this->assertNull($user->getAddress());
$this->assertEquals('FabioBatSilva1', $user->name);
2012-06-11 18:21:22 -03:00
$this->_em->remove($user);
$this->_em->flush();
$this->_em->clear();
2012-06-11 17:41:00 -03:00
$this->assertNull($this->_em->find(User::class, $id));
2012-06-11 17:41:00 -03:00
}
}