2014-03-18 18:00:43 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\ORM\Event\LifecycleEventArgs;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-3033
|
|
|
|
*/
|
|
|
|
class DDC3033Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
public function testIssue()
|
|
|
|
{
|
|
|
|
$this->_schemaTool->createSchema(array(
|
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3033User'),
|
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3033Product'),
|
|
|
|
));
|
|
|
|
|
|
|
|
$user = new DDC3033User();
|
2014-03-23 15:35:54 +04:00
|
|
|
$user->name = "Test User";
|
2014-03-18 18:00:43 +04:00
|
|
|
$this->_em->persist($user);
|
|
|
|
|
|
|
|
$user2 = new DDC3033User();
|
2014-03-23 15:35:54 +04:00
|
|
|
$user2->name = "Test User 2";
|
2014-03-18 18:00:43 +04:00
|
|
|
$this->_em->persist($user2);
|
|
|
|
|
|
|
|
$product = new DDC3033Product();
|
2014-03-19 01:10:15 +04:00
|
|
|
$product->title = "Test product";
|
|
|
|
$product->buyers[] = $user;
|
2014-03-18 18:00:43 +04:00
|
|
|
|
2014-03-18 18:04:48 +04:00
|
|
|
$this->_em->persist($product);
|
2014-03-18 18:00:43 +04:00
|
|
|
$this->_em->flush();
|
|
|
|
|
2014-03-19 01:10:15 +04:00
|
|
|
$product->title = "Test Change title";
|
|
|
|
$product->buyers[] = $user2;
|
2014-03-18 18:00:43 +04:00
|
|
|
|
2014-03-18 18:04:48 +04:00
|
|
|
$this->_em->persist($product);
|
|
|
|
$this->_em->flush();
|
2014-03-18 18:00:43 +04:00
|
|
|
|
2014-03-18 18:04:48 +04:00
|
|
|
$expect = array(
|
2014-03-18 18:00:43 +04:00
|
|
|
'title' => array(
|
2014-03-18 18:04:48 +04:00
|
|
|
0 => 'Test product',
|
|
|
|
1 => 'Test Change title',
|
|
|
|
),
|
|
|
|
);
|
2014-03-18 18:00:43 +04:00
|
|
|
|
2014-03-19 01:10:15 +04:00
|
|
|
$this->assertEquals($expect, $product->changeSet);
|
2014-03-18 18:00:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Table
|
|
|
|
* @Entity @HasLifecycleCallbacks
|
|
|
|
*/
|
|
|
|
class DDC3033Product
|
|
|
|
{
|
|
|
|
public $changeSet = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var integer $id
|
|
|
|
*
|
|
|
|
* @Column(name="id", type="integer")
|
|
|
|
* @Id
|
|
|
|
* @GeneratedValue(strategy="AUTO")
|
|
|
|
*/
|
2014-03-19 01:10:15 +04:00
|
|
|
public $id;
|
2014-03-18 18:00:43 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string $title
|
|
|
|
*
|
|
|
|
* @Column(name="title", type="string", length=255)
|
|
|
|
*/
|
2014-03-19 01:10:15 +04:00
|
|
|
public $title;
|
2014-03-18 18:00:43 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @ManyToMany(targetEntity="DDC3033User")
|
|
|
|
* @JoinTable(
|
2014-03-19 01:10:15 +04:00
|
|
|
* name="user_purchases_3033",
|
2014-03-18 18:00:43 +04:00
|
|
|
* joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")},
|
|
|
|
* inverseJoinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}
|
|
|
|
* )
|
|
|
|
*/
|
2014-03-19 01:10:15 +04:00
|
|
|
public $buyers;
|
2014-03-18 18:00:43 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->buyers = new ArrayCollection();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @PreUpdate
|
|
|
|
*/
|
|
|
|
public function preUpdate(LifecycleEventArgs $eventArgs)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @PostUpdate
|
|
|
|
*/
|
|
|
|
public function postUpdate(LifecycleEventArgs $eventArgs)
|
|
|
|
{
|
|
|
|
$em = $eventArgs->getEntityManager();
|
|
|
|
$uow = $em->getUnitOfWork();
|
|
|
|
$entity = $eventArgs->getEntity();
|
|
|
|
$classMetadata = $em->getClassMetadata(get_class($entity));
|
|
|
|
|
2014-03-18 18:04:48 +04:00
|
|
|
$uow->computeChangeSet($classMetadata, $entity);
|
2014-03-18 18:00:43 +04:00
|
|
|
$this->changeSet = $uow->getEntityChangeSet($entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Table
|
|
|
|
* @Entity @HasLifecycleCallbacks
|
|
|
|
*/
|
|
|
|
class DDC3033User
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var integer
|
|
|
|
*
|
|
|
|
* @Column(name="id", type="integer")
|
|
|
|
* @Id
|
|
|
|
* @GeneratedValue(strategy="AUTO")
|
|
|
|
*/
|
2014-03-19 01:10:15 +04:00
|
|
|
public $id;
|
2014-03-18 18:00:43 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*
|
|
|
|
* @Column(name="title", type="string", length=255)
|
|
|
|
*/
|
2014-03-23 15:35:54 +04:00
|
|
|
public $name;
|
2014-03-18 18:00:43 +04:00
|
|
|
}
|