public function testManyEmbedded() { $album = new Album('Jon'); $album->addSong(new Song('Song #1')); $album->addSong(new Song('Song #2')); $this->dm->persist($album); $this->dm->flush(); $songs = $album->getSongs(); $songs[0]->setName('Song #1 Changed'); $songs->add(new Song('Song #3')); $this->dm->flush(); $test = $this->dm->getDocumentCollection('Documents\\Album')->findOne(array('name' => 'Jon')); $this->assertEquals('Song #1 Changed', $test['songs'][0]['name']); $album->setName('jwage'); $songs[1]->setName('ok'); $songs->add(new Song('Song #4')); $songs->add(new Song('Song #5')); unset($songs[0]); $this->dm->flush(); $test = $this->dm->getDocumentCollection('Documents\\Album')->findOne(array('name' => 'jwage')); $this->assertEquals('jwage', $test['name']); $this->assertEquals('ok', $test['songs'][0]['name']); $this->assertEquals('Song #3', $test['songs'][1]['name']); $this->assertEquals('Song #4', $test['songs'][2]['name']); $this->assertEquals('Song #5', $test['songs'][3]['name']); $this->assertEquals(4, count($test['songs'])); $songs->clear(); $this->dm->flush(); $this->dm->clear(); $test = $this->dm->getDocumentCollection('Documents\\Album')->findOne(array('name' => 'jwage')); $this->assertFalse(isset($test['songs'])); }
public function testGetFieldValue() { $document = new Album('ten'); $metadata = $this->dm->getClassMetadata('Documents\\Album'); $this->assertEquals($document->getName(), $metadata->getFieldValue($document, 'name')); }