예제 #1
0
 public function testCollections()
 {
     $bar = new Bar("Jon's Pub");
     $bar->addLocation(new Location('West Nashville'));
     $bar->addLocation(new Location('East Nashville'));
     $bar->addLocation(new Location('North Nashville'));
     $this->dm->persist($bar);
     $this->dm->flush();
     $this->dm->clear();
     $bar = $this->dm->find('Documents\\Bars\\Bar', $bar->getId());
     $this->assertNotNull($bar);
     $locations = $bar->getLocations();
     unset($locations[0]);
     $locations[1]->setName('changed');
     $this->dm->flush();
     $this->dm->clear();
     $test = $this->dm->getDocumentCollection('Documents\\Bars\\Bar')->findOne();
     $this->assertEquals(2, count($test['locations']));
     $bar = $this->dm->find('Documents\\Bars\\Bar', $bar->getId());
     $this->assertNotNull($bar);
     $locations = $bar->getLocations();
     $this->assertEquals(2, count($locations));
     $this->assertEquals('changed', $locations[0]->getName());
     unset($locations[0], $locations[1]);
     $this->dm->flush();
     $this->dm->clear();
     $bar = $this->dm->find('Documents\\Bars\\Bar', $bar->getId());
     $this->assertNotNull($bar);
     $locations = $bar->getLocations();
     $this->assertEquals(0, count($locations));
     $bar->addLocation(new Location('West Nashville'));
     $bar->addLocation(new Location('East Nashville'));
     $bar->addLocation(new Location('North Nashville'));
     $this->dm->flush();
     $this->dm->clear();
     $bar = $this->dm->find('Documents\\Bars\\Bar', $bar->getId());
     $this->assertEquals($bar->getId(), $this->dm->getUnitOfWork()->getDocumentIdentifier($bar));
     $this->assertNotNull($bar);
     $locations = $bar->getLocations();
     $this->assertEquals(3, count($locations));
     $locations = $bar->getLocations();
     $locations->clear();
     $this->assertEquals(0, count($locations));
     $this->dm->flush();
     $this->dm->clear();
     $bar = $this->dm->find('Documents\\Bars\\Bar', $bar->getId());
     $locations = $bar->getLocations();
     $this->assertEquals(0, count($locations));
     $this->dm->flush();
     $bar->setLocations(new ArrayCollection([new Location('Cracow')]));
     $this->uow->computeChangeSets();
     $changeSet = $this->uow->getDocumentChangeSet($bar);
     $this->assertNotEmpty($changeSet['locations']);
     $this->assertSame($locations, $changeSet['locations'][0]);
     $this->assertSame($bar->getLocations(), $changeSet['locations'][1]);
 }
예제 #2
0
 public function testCollections()
 {
     $bar = new Bar("Jon's Pub");
     $bar->addLocation(new Location('West Nashville'));
     $bar->addLocation(new Location('East Nashville'));
     $bar->addLocation(new Location('North Nashville'));
     $this->dm->persist($bar);
     $this->dm->flush();
     $this->dm->clear();
     $bar = $this->dm->find('Documents\\Bars\\Bar', $bar->getId());
     $this->assertNotNull($bar);
     $locations = $bar->getLocations();
     unset($locations[0]);
     $locations[1]->setName('changed');
     $this->dm->flush();
     $this->dm->clear();
     $test = $this->dm->getDocumentCollection('Documents\\Bars\\Bar')->findOne();
     $this->assertEquals(2, count($test['locations']));
     $bar = $this->dm->find('Documents\\Bars\\Bar', $bar->getId());
     $this->assertNotNull($bar);
     $locations = $bar->getLocations();
     $this->assertEquals(2, count($locations));
     $this->assertEquals('changed', $locations[0]->getName());
     unset($locations[0], $locations[1]);
     $this->dm->flush();
     $this->dm->clear();
     $bar = $this->dm->find('Documents\\Bars\\Bar', $bar->getId());
     $this->assertNotNull($bar);
     $locations = $bar->getLocations();
     $this->assertEquals(0, count($locations));
     $bar->addLocation(new Location('West Nashville'));
     $bar->addLocation(new Location('East Nashville'));
     $bar->addLocation(new Location('North Nashville'));
     $this->dm->flush();
     $this->dm->clear();
     $bar = $this->dm->find('Documents\\Bars\\Bar', $bar->getId());
     $this->assertEquals($bar->getId(), $this->dm->getUnitOfWork()->getDocumentIdentifier($bar));
     $this->assertNotNull($bar);
     $locations = $bar->getLocations();
     $this->assertEquals(3, count($locations));
     $locations = $bar->getLocations();
     $locations->clear();
     $this->assertEquals(0, count($locations));
     $this->dm->flush(array('safe' => true));
     $this->dm->clear();
     $bar = $this->dm->find('Documents\\Bars\\Bar', $bar->getId());
     $locations = $bar->getLocations();
     $this->assertEquals(0, count($locations));
 }
예제 #3
0
 public function testSimple()
 {
     $bar = new Bar("Jon's Pub");
     $bar->addLocation(new Location('West Nashville'));
     $bar->addLocation(new Location('East Nashville'));
     $bar->addLocation(new Location('North Nashville'));
     $this->dm->persist($bar);
     $this->dm->flush();
     $this->dm->clear();
     $bar = $this->dm->find('Documents\\Bars\\Bar', $bar->getId());
     $locations = $bar->getLocations();
     unset($locations[0]);
     $this->dm->flush();
     $test = $this->dm->getDocumentCollection('Documents\\Bars\\Bar')->findOne();
     $this->assertEquals(2, count($test['locations']));
 }
예제 #4
0
 public function testTypeClass()
 {
     $bar = new Bar("Jon's Pub");
     $bar->addLocation(new Location('West Nashville'));
     $bar->addLocation(new Location('East Nashville'));
     $bar->addLocation(new Location('North Nashville'));
     $this->dm->persist($bar);
     $this->dm->flush();
     $this->dm->clear();
     /** @var $test Bar */
     $test = $this->dm->find('Documents\\Bars\\Bar', $bar->getId());
     /** @var $collection PersistentCollection */
     $collection = $test->getLocations();
     $this->assertInstanceOf('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata', $collection->getTypeClass());
 }