public function testIdentityMap() { $user = new \Documents\User(); $user->setUsername('jwage'); $this->dm->persist($user); $this->dm->flush(); $qb = $this->dm->createQueryBuilder('Documents\\User')->field('id')->equals($user->getId()); $user = $qb->getQuery()->getSingleResult(); $this->assertSame($user, $user); $this->dm->clear(); $user2 = $qb->getQuery()->getSingleResult(); $this->assertNotSame($user, $user2); $user2->setUsername('changed'); $qb->refresh(); $user3 = $qb->getQuery()->getSingleResult(); $this->assertSame($user2, $user3); $this->assertEquals('jwage', $user3->getUsername()); $user3->setUsername('changed'); $qb->refresh(false); $user4 = $qb->getQuery()->getSingleResult(); $this->assertEquals('changed', $user4->getUsername()); $qb = $this->dm->createQueryBuilder('Documents\\USer')->findAndUpdate()->returnNew(true)->hydrate(true)->field('username')->equals('jwage')->field('count')->inc(1); $result = $qb->getQuery()->execute(); $result = $qb->refresh(false)->getQuery()->execute(); $this->assertEquals(1, $result->getCount()); $result = $qb->refresh(true)->getQuery()->execute(); $this->assertEquals(3, $result->getCount()); }
public function testPrePersistIsCalledFromMappedSuperClass() { $user = new \Documents\User(); $user->setUsername('test'); $this->dm->persist($user); $this->dm->flush(); $this->assertTrue($user->persisted); }
public function testQueryIdIn() { $user = new \Documents\User(); $user->setUsername('jwage'); $this->dm->persist($user); $this->dm->flush(); $mongoId = new \MongoId($user->getId()); $ids = array($mongoId); $qb = $this->dm->createQueryBuilder('Documents\\User')->field('_id')->in($ids); $query = $qb->getQuery(); $results = $query->toArray(); $this->assertEquals(1, count($results)); }
public function testIdentityMap() { $user = new \Documents\User(); $user->setUsername('jwage'); $this->dm->persist($user); $this->dm->flush(); $query = $this->dm->createQuery('Documents\\User')->where('id', $user->getId()); $user = $query->getSingleResult(); $this->assertSame($user, $user); $this->dm->clear(); $user2 = $query->getSingleResult(); $this->assertNotSame($user, $user2); }
public function testLockUnversionedDocumentThrowsException() { $user = new \Documents\User(); $user->setUsername('test'); $this->dm->persist($user); $this->dm->flush(); $this->setExpectedException('Doctrine\\ODM\\MongoDB\\LockException', 'Document Documents\\User is not versioned.'); $this->dm->lock($user, LockMode::OPTIMISTIC); }
public function testPrime() { $group1 = new \Documents\Group(); $group2 = new \Documents\Group(); $user1 = new \Documents\User(); $user1->setGroups(new ArrayCollection(array($group1, $group2))); $account1 = new \Documents\Account(); $user1->setAccount($account1); $user2 = new \Documents\User(); $user2->setGroups(new ArrayCollection(array($group1, $group2))); $account2 = new \Documents\Account(); $user2->setAccount($account2); $this->dm->persist($group1); $this->dm->persist($group2); $this->dm->persist($account1); $this->dm->persist($user1); $this->dm->persist($account2); $this->dm->persist($user2); $this->dm->flush(); $this->dm->clear(); $qb = $this->dm->createQueryBuilder('Documents\\User')->field('groups')->prime(true)->field('account')->prime(true); $query = $qb->getQuery(); $users = $query->execute(); foreach ($users as $user) { $this->assertTrue($user->getAccount()->__isInitialized__); foreach ($user->getGroups() as $group) { $this->assertNotEquals('Proxies\\DocumentsGroupProxy', get_class($group)); } } $this->dm->clear(); $test = false; $qb = $this->dm->createQueryBuilder('Documents\\User')->field('groups')->prime(function () use(&$test) { $test = true; }); $query = $qb->getQuery(); $users = $query->execute(); $this->assertTrue($test); }
private function insertTestData() { $user1 = new \Documents\User(); $user1->setUsername('alcaeus'); $user2 = new \Documents\User(); $user2->setUsername('malarzm'); $this->dm->persist($user1); $this->dm->persist($user2); $simpleReferenceUser = new \Documents\SimpleReferenceUser(); $simpleReferenceUser->user = $user1; $simpleReferenceUser->addUser($user1); $simpleReferenceUser->addUser($user2); $this->dm->persist($simpleReferenceUser); $this->dm->flush(); }
public function testEmbeddedDocumentChangeSets() { $address = new \Documents\Address(); $user = new \Documents\User(); $user->setAddress($address); $this->uow->persist($user); $this->uow->computeChangeSets(); $changeSet = $this->uow->getDocumentChangeSet($address); $this->assertNotEmpty($changeSet); $this->uow->commit(); $address->setCity('Nashville'); $this->uow->computeChangeSets(); $changeSet = $this->uow->getDocumentChangeSet($address); $this->assertTrue(isset($changeSet['city'])); $this->assertEquals('Nashville', $changeSet['city'][1]); }