Exemple #1
0
 public function testTest()
 {
     $article = new \Documents\Article();
     $article->setTitle('Test Title');
     $article->setBody('Test Body');
     $this->dm->persist($article);
     $this->dm->flush();
     $this->dm->clear();
     $qb = $this->dm->createQueryBuilder('Documents\\Article')->select('_id', 'title');
     $q = $qb->getQuery();
     $document = $q->getSingleResult();
     $this->assertEquals('Test Title', $document->getTitle());
     $this->assertNull($document->getBody());
     $document->setTitle('changed');
     $this->dm->flush();
     $check = $this->dm->getDocumentCollection('Documents\\Article')->findOne();
     $this->assertEquals('changed', $check['title']);
     $this->assertEquals('Test Body', $check['body']);
 }
<?php

require_once "bootstrap.php";
$article1 = new Documents\Article();
$article1->setTitle("Who is John Galt?");
$article1->setBody("Find out!");
$article1->addTag("Philosophy");
$article2 = new Documents\Article();
$article2->setTitle("Human Action");
$article2->setBody("Find out!");
$article2->addTag("Philosophy");
$article2->addTag("Economics");
$article3 = new Documents\Article();
$article3->setTitle("Design Patterns");
$article3->setBody("Find out!");
$article3->addTag("Computer Science");
$dm->persist($article1);
$dm->persist($article2);
$dm->persist($article3);
$dm->flush();
$dm->clear();
<?php

require_once "bootstrap.php";
$article = new Documents\Article();
$article->setTitle("Who is John Galt?");
$article->setBody("Find out!");
$article->addTag("Philosophy");
$dm->persist($article);
$dm->flush();
$dm->clear();
$articles = $dm->getRepository('Documents\\Article')->findAll();
foreach ($articles as $article) {
    echo "ID: " . $article->getId() . "\n";
    echo "Title: " . $article->getTitle() . ", " . $article->getCreated()->format('d.m.Y, H:i') . "\n";
    echo "Tags: \n";
    foreach ($article->getTags() as $tag) {
        echo "  - " . $tag->getName() . "\n";
    }
    echo "\n";
}
<?php

require_once 'bootstrap.php';
$article1 = new Documents\Article();
$article1->setName('Foo');
$article1->setId('MyArticle' . time());
$section1 = new Documents\Section('Part 1', 'The journey begins ....');
$section2 = new Documents\Section('Part 2', 'Something happens ....');
$section3 = new Documents\Section('Part 3', 'Everyone goes home.');
$article1->addSection($section1);
$article1->addSection($section2);
$article1->addSection($section3);
$dm->persist($article1);
$dm->flush();