From 263822fd191d647a0a2e997d07fc0449553b826b Mon Sep 17 00:00:00 2001 From: Thomas Lallement Date: Tue, 18 Mar 2014 15:00:43 +0100 Subject: [PATCH] Failing Test (since commit 53a5a48aed7d87aa1533c0bcbd72e41b686527d8) Hi, It seems to be a regression since the commit https://github.com/doctrine/doctrine2/commit/53a5a48aed7d87aa1533c0bcbd72e41b686527d8 Doctrine\ORM\PersistentCollection can be populated in $changeSet if you set a PreUpdate and PostUpdate event. Original issue: http://www.doctrine-project.org/jira/browse/DDC-3033 --- .../ORM/Functional/Ticket/DDC3033Test.php | 219 ++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php new file mode 100644 index 000000000..177fb0976 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php @@ -0,0 +1,219 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3033User'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3033Product'), + )); + + $user = new DDC3033User(); + $user->setTitle("Test User"); + $this->_em->persist($user); + + $user2 = new DDC3033User(); + $user2->setTitle("Test User 2"); + $this->_em->persist($user2); + + $product = new DDC3033Product(); + $product->setTitle("Test product"); + $product->addBuyer($user); + + $this->_em->persist($product); + $this->_em->flush(); + + $product->setTitle("Test Change title"); + $product->addBuyer($user2); + + $this->_em->persist($product); + $this->_em->flush(); + + $expect = array( + 'title' => array( + 0 => 'Test product', + 1 => 'Test Change title', + ), + ); + + $this->assertEquals(print_r($expect, true), print_r($product->changeSet, true)); + } +} + +/** + * @Table + * @Entity @HasLifecycleCallbacks + */ +class DDC3033Product +{ + public $changeSet = array(); + + /** + * @var integer $id + * + * @Column(name="id", type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + private $id; + + /** + * @var string $title + * + * @Column(name="title", type="string", length=255) + */ + private $title; + + /** + * @ManyToMany(targetEntity="DDC3033User") + * @JoinTable( + * name="user_purchases", + * joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")}, + * inverseJoinColumns={@JoinColumn(name="user_id", referencedColumnName="id")} + * ) + */ + private $buyers; + + /** + * Default constructor + */ + public function __construct() + { + $this->buyers = new ArrayCollection(); + } + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $title + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * Get title + * + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $buyers + */ + public function setBuyers($buyers) + { + $this->buyers = $buyers; + } + + /** + * @return string + */ + public function getBuyers() + { + return $this->buyers; + } + + /** + * @param DDC3033User $buyer + */ + public function addBuyer(DDC3033User $buyer) + { + $this->buyers[] = $buyer; + } + + /** + * @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)); + + $uow->computeChangeSet($classMetadata, $entity); + $this->changeSet = $uow->getEntityChangeSet($entity); + } +} + +/** + * @Table + * @Entity @HasLifecycleCallbacks + */ +class DDC3033User +{ + /** + * @var integer + * + * @Column(name="id", type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + private $id; + + /** + * @var string + * + * @Column(name="title", type="string", length=255) + */ + private $title; + + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * Set title + * + * @param string $title + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * Get title + * + * @return string + */ + public function getTitle() + { + return $this->title; + } +}