Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function attachCommentary(Commentary $comm)
 {
     $comm->setUuid(new \MongoId());
     array_unshift($this->commentary, $comm);
     // manage capped collection of commentaries :
     if (!is_null($this->cappComm) && count($this->commentary) > $this->cappComm) {
         array_splice($this->commentary, $this->cappComm - count($this->commentary));
     }
 }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function initialize()
 {
     parent::initialize();
     $author = [];
     foreach (['kirk', 'spock', 'mccoy'] as $nick) {
         $author[] = new Author($nick);
     }
     $doc0 = new SmallTalk($author[0]);
     $doc1 = clone $doc0;
     $doc0->report($author[1]);
     $doc2 = clone $doc0;
     $comm = new Commentary($author[1]);
     $comm->report($author[2]);
     $doc1->attachCommentary($comm);
     $doc3 = clone $doc1;
     $this->getService('dokudoki.repository')->batchPersist([$doc0, $doc1, $doc2, $doc3]);
 }
Exemplo n.º 3
0
 protected final function createDocument()
 {
     $author = [new Author('spock'), new Author('kirk'), new Author('scotty')];
     $sut = $this->createRootEntity($author[0]);
     // adding 'like' to the post
     foreach ($author as $a) {
         $sut->addFan($a);
     }
     // adding comments to the post
     foreach ($author as $a) {
         $comm = new Commentary($a);
         $comm->setMessage("a comment from " . $a->getNickname());
         // adding 'like' to each comment
         foreach ($author as $c) {
             $comm->addFan($c);
         }
         $sut->attachCommentary($comm);
     }
     return $sut;
 }
Exemplo n.º 4
0
 /**
  * @depends testILikeThat
  */
 public function testIUnlikeThat(Commentary $comm)
 {
     $this->assertEquals(1, $comm->getFanCount());
     $this->repository->expects($this->once())->method('findByPk')->with($this->equalTo('54390582e3f43405428b4568'))->will($this->returnValue($this->document));
     $this->document->expects($this->once())->method('getCommentaryByUuid')->with($this->equalTo('123'))->will($this->returnValue($comm));
     $this->sut->iUnlikeThat('54390582e3f43405428b4568', '123');
     $this->assertEquals(0, $comm->getFanCount());
 }
Exemplo n.º 5
0
    }
    public function offsetUnset($offset)
    {
        foreach ($this->wrapped as $idx => $comm) {
            if ($comm->getUuid() === $offset) {
                unset($this->wrapped[$idx]);
                break;
            }
        }
    }
    public function rewind()
    {
        $this->ptr = 0;
    }
    public function valid()
    {
        return array_key_exists($this->ptr, $this->wrapped);
    }
}
$comment = [];
for ($k = 0; $k < 1000; $k++) {
    $obj = new Commentary(new Author("user {$k}"));
    $obj->setMessage("aaaaaaaaaaaaa {$k}");
    $comment[$k] = $obj;
}
$stop = microtime(true);
printf("%.0f kB\n", memory_get_peak_usage(true) / 1000.0);
$it = new CommentaryIterator($comment);
//echo $it->count() . PHP_EOL;
printf("%.0f kB\n", memory_get_peak_usage(true) / 1000.0);
$it[] = 'oto';
Exemplo n.º 6
0
 protected function initDbWithOnePublishingWithReportedComment()
 {
     $author = [];
     foreach (['kirk', 'spock', 'mccoy'] as $nick) {
         $author[] = new Author($nick);
     }
     $doc = new SmallTalk($author[0]);
     $comm = new Commentary($author[1]);
     $comm->report($author[2]);
     $comm->report($author[0]);
     $doc->attachCommentary($comm);
     $this->coll->drop();
     $this->repo->persist($doc);
 }