Esempio n. 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']);
 }
Esempio n. 2
0
<?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();
Esempio n. 3
0
<?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";
}