Beispiel #1
0
 public function testRefresh()
 {
     $o = new ShardedOne();
     $this->dm->persist($o);
     $this->dm->flush();
     $this->dm->refresh($o);
     $queries = $this->ql->getAll();
     $lastQuery = end($queries);
     $this->assertTrue($lastQuery['findOne']);
     $this->assertContains('k', array_keys($lastQuery['query']));
     $this->assertEquals($o->key, $lastQuery['query']['k']);
 }
Beispiel #2
0
 public function testAtomicSetUpdatesAllNestedCollectionsInOneQuery()
 {
     // Create a book which has one chapter with one page.
     $chapter1 = new Chapter();
     $chapter1->pages->add(new Page(1));
     $book = new Book('title');
     $book->chapters->add($chapter1);
     $this->dm->persist($book);
     // Saving this book should result in 1 query since we use strategy="atomicSet"
     $this->dm->flush();
     $this->assertCount(1, $this->ql, 'Inserting a book with one chapter and page requires one query');
     // Simulate another PHP request which loads this record and tries to add an embedded document two levels deep...
     $this->dm->clear();
     $book = $this->dm->getRepository(Book::CLASSNAME)->findOneBy(array('_id' => $book->id));
     // Now we add a new "page" to the only chapter in this book.
     $firstChapter = $book->chapters->first();
     $firstChapter->pages->add(new Page(2));
     // Updating this book should result in 1 query since we use strategy="atomicSet"
     $this->ql->clear();
     $this->dm->flush();
     $this->assertCount(1, $this->ql, 'Adding a page to the first chapter of the book requires one query');
     // this is failing if lifecycle callback postUpdate is recomputing change set
     $book = $this->dm->getRepository(Book::CLASSNAME)->findOneBy(array('_id' => $book->id));
     $this->assertEquals(2, $book->chapters->first()->pages->count(), "Two page objects are expected in the first chapter of the book.");
 }
Beispiel #3
0
 public function testUpdatingNestedCollectionWhileDeletingParent()
 {
     $user = new AtomicSetUser('Jon');
     $user->inception[0] = new AtomicSetInception('start');
     $user->inception[0]->many[0] = new AtomicSetInception('start.many.0');
     $user->inception[0]->many[0]->many[0] = new AtomicSetInception('start.many.0.many.0');
     $user->inception[0]->many[1] = new AtomicSetInception('start.many.1');
     $user->inception[0]->many[1]->many[0] = new AtomicSetInception('start.many.1.many.0');
     $this->dm->persist($user);
     $this->dm->flush();
     $this->assertCount(1, $this->ql, 'Inserting a document with nested embed-many collections requires one query');
     $this->dm->clear();
     $user = $this->dm->getRepository(get_class($user))->find($user->id);
     $this->assertCount(1, $user->inception);
     $this->assertEquals($user->inception[0]->value, 'start');
     $this->assertCount(2, $user->inception[0]->many);
     $this->assertEquals($user->inception[0]->many[0]->value, 'start.many.0');
     $this->assertCount(1, $user->inception[0]->many[0]->many);
     $this->assertEquals($user->inception[0]->many[0]->many[0]->value, 'start.many.0.many.0');
     $this->assertEquals($user->inception[0]->many[1]->value, 'start.many.1');
     $this->assertCount(1, $user->inception[0]->many[0]->many);
     $this->assertEquals($user->inception[0]->many[1]->many[0]->value, 'start.many.1.many.0');
     $user->inception[0]->many[0]->many[0]->value = 'start.many.0.many.0-changed';
     $user->inception[0]->many[0]->many[1] = new AtomicSetInception('start.many.0.many.1');
     $user->inception[0]->many[0]->many->clear();
     $user->inception[0]->many[1]->many[1] = new AtomicSetInception('start.many.1.many.1');
     $user->inception[0]->many[1] = new AtomicSetInception('start.many.1');
     $user->inception[0]->many[1]->many[0] = new AtomicSetInception('start.many.1.many.0-new');
     $this->ql->clear();
     $this->dm->flush();
     $this->assertCount(1, $this->ql, 'Updating nested collections while deleting parents requires one query');
     $this->dm->clear();
     $user = $this->dm->getRepository(get_class($user))->find($user->id);
     $this->assertCount(1, $user->inception);
     $this->assertEquals($user->inception[0]->value, 'start');
     $this->assertCount(2, $user->inception[0]->many);
     $this->assertEquals($user->inception[0]->many[0]->value, 'start.many.0');
     $this->assertCount(0, $user->inception[0]->many[0]->many);
     $this->assertEquals($user->inception[0]->many[1]->value, 'start.many.1');
     $this->assertCount(1, $user->inception[0]->many[1]->many);
     $this->assertEquals($user->inception[0]->many[1]->many[0]->value, 'start.many.1.many.0-new');
 }
 public function testSchedulingCollectionDeletionAfterSchedulingForUpdate()
 {
     $user = new User();
     $user->addPhonenumber(new Phonenumber('12345678'));
     $this->dm->persist($user);
     $this->dm->flush();
     $user->addPhonenumber(new Phonenumber('87654321'));
     $this->uow->computeChangeSet($this->dm->getClassMetadata(get_class($user)), $user);
     $this->assertTrue($this->uow->isCollectionScheduledForUpdate($user->getPhonenumbers()));
     $this->assertFalse($this->uow->isCollectionScheduledForDeletion($user->getPhonenumbers()));
     $user->getPhonenumbers()->clear();
     $this->uow->computeChangeSet($this->dm->getClassMetadata(get_class($user)), $user);
     $this->assertFalse($this->uow->isCollectionScheduledForUpdate($user->getPhonenumbers()));
     $this->assertTrue($this->uow->isCollectionScheduledForDeletion($user->getPhonenumbers()));
     $this->ql->clear();
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->find(get_class($user), $user->getId());
     $this->assertCount(0, $user->getPhonenumbers());
 }