Browse files

Fix getPartialReference() test to not use invalid identifier per mapping

This leaves a todo item for registerManaged(). As-is, this test failed because registering a document with an identifier not valid for its mapping would lead to an inconsistency in the UnitOfWork maps. The CmsUser document's identifier uses IdType, so we should use a MongoId (or compatible string) here.
  • Loading branch information...
1 parent dad59aa commit 681c3dba0274356116a65d34a502a7a819f87d96 @jmikola jmikola committed Jan 14, 2014
7 lib/Doctrine/ODM/MongoDB/UnitOfWork.php
@@ -2837,6 +2837,13 @@ public function size()
* Registers a document as managed.
+ * TODO: This method assumes that $id is a valid PHP identifier for the
+ * document class. If the class expects its database identifier to be a
+ * MongoId, and an incompatible $id is registered (e.g. an integer), the
+ * document identifiers map will become inconsistent with the identity map.
+ * In the future, we may want to round-trip $id through a PHP and database
+ * conversion and throw an exception if it's inconsistent.
+ *
* @param object $document The document.
* @param array $id The identifier values.
* @param array $data The original document data.
5 tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php
@@ -59,9 +59,10 @@ public function testGetFilterCollection()
public function testGetPartialReference()
- $user = $this->dm->getPartialReference('Documents\CmsUser', 42);
+ $id = new \MongoId();
+ $user = $this->dm->getPartialReference('Documents\CmsUser', $id);
- $this->assertEquals(42, $user->id);
+ $this->assertEquals($id, $user->id);

0 comments on commit 681c3db

Please sign in to comment.