2012-06-11 17:41:00 -03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
use Doctrine\Tests\Models\Quote\Group;
|
|
|
|
use Doctrine\Tests\Models\Quote\Phone;
|
2012-06-11 17:41:00 -03:00
|
|
|
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()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
try {
|
2016-12-07 23:33:41 +01:00
|
|
|
$this->_schemaTool->createSchema(
|
|
|
|
[
|
2016-12-08 18:01:04 +01:00
|
|
|
$this->_em->getClassMetadata(User::class),
|
|
|
|
$this->_em->getClassMetadata(Group::class),
|
|
|
|
$this->_em->getClassMetadata(Phone::class),
|
|
|
|
$this->_em->getClassMetadata(Address::class),
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|
2012-06-11 17:41:00 -03:00
|
|
|
} catch(\Exception $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$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);
|
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$user = $this->_em->find(User::class, $id);
|
2012-06-11 18:21:22 -03:00
|
|
|
$address = $user->getAddress();
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$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();
|
|
|
|
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$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);
|
2016-12-07 23:33:41 +01:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$this->assertNull($this->_em->find(User::class, $id));
|
2012-06-11 17:41:00 -03:00
|
|
|
}
|
|
|
|
|
2014-04-07 14:43:25 +02:00
|
|
|
}
|