diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2349Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2349Test.php new file mode 100644 index 0000000000..ded5519a5c --- /dev/null +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2349Test.php @@ -0,0 +1,41 @@ +dm->persist($customer); + $this->dm->persist($order); + $this->dm->flush(); + $this->dm->clear(); + + $orderId = GH2349Order::ID; + + $order = $this->dm->getRepository(GH2349Order::class)->find($orderId); + + // Fetch a list of Customers from the DB. Any customer object that was referenced in the above order is still + // a proxy object, however it will not have the defaults set for the un-managed $domainEvents property. + $customers = $this->dm->getRepository(GH2349Customer::class)->findAll(); + + foreach ($customers as $customer) { + $customer->doSomeUpdate(); // This will trigger an error as we try to append to the non-existing $domainEvents property + } + } +} diff --git a/tests/Documents74/GH2349Customer.php b/tests/Documents74/GH2349Customer.php new file mode 100644 index 0000000000..ad619aff42 --- /dev/null +++ b/tests/Documents74/GH2349Customer.php @@ -0,0 +1,39 @@ +id = self::ID; + $this->name = $name; + } + + public function doSomeUpdate(): void + { + $this->domainEvents[] = 'a new event!'; + } + + public function getEvents(): array + { + return $this->domainEvents; + } +} diff --git a/tests/Documents74/GH2349Order.php b/tests/Documents74/GH2349Order.php new file mode 100644 index 0000000000..1ff776cd57 --- /dev/null +++ b/tests/Documents74/GH2349Order.php @@ -0,0 +1,28 @@ +id = (string) new ObjectId(self::ID); + $this->customer = $customer; + } +}