Author: D. Barsotti (daniel.barsotti@liip.ch)
Inheritance: extends ArrayIterator, implements PHPCR\Observation\EventJournalInterface
Beispiel #1
0
 public function testSkipTo()
 {
     $xml = $this->buildSkipToTestData();
     $doc = new \DOMDocument();
     $doc->loadXML($xml);
     $journal = new EventJournal($this->factory, $this->session, $doc);
     $firstEvent = $journal->current();
     // ----- Skip to start of list
     $journal->skipTo(-1);
     $this->assertSame($firstEvent, $journal->current());
     $journal->skipTo(100);
     $this->assertSame($firstEvent, $journal->current());
     $journal->skipTo(110);
     $this->assertNotSame($firstEvent, $journal->current());
     $this->assertNotSame($firstEvent, $journal->current());
     // ----- Now skipping to an earlier date should not have any effect
     $journal->skipTo(100);
     $this->assertNotSame($firstEvent, $journal->current());
     // ----- Skip to end of list
     $journal->skipTo(490);
     $this->assertEquals(490, $journal->current()->getDate());
     $journal->next();
     $this->assertEquals(500, $journal->current()->getDate());
     $journal->next();
     $this->assertNull($journal->current());
 }
 public function testIterator()
 {
     $filter = new EventFilter($this->factory, $this->session);
     $event1 = new Event($this->factory, $this->getNodeTypeManager());
     $event1->setDate(2);
     $event2 = new Event($this->factory, $this->getNodeTypeManager());
     $event2->setDate(3);
     $this->transport->expects($this->once())->method('getEvents')->with(2, $filter, $this->session)->will($this->returnValue(new \ArrayIterator(array($event1, $event2))));
     $journal = new EventJournal($this->factory, $filter, $this->session, $this->transport);
     $journal->skipTo(2);
     $this->assertTrue($journal->valid());
     $this->assertSame($event1, $journal->current());
     $journal->next();
     $this->assertTrue($journal->valid());
     $this->assertSame($event2, $journal->current());
     $journal->next();
     $this->assertFalse($journal->valid());
     $journal->rewind();
     $this->assertTrue($journal->valid());
     $this->assertSame($event1, $journal->current());
 }