Beispiel #1
0
 function testAppendAndFlushing()
 {
     $flushContainer = new \stdClass();
     $flushContainer->data = array();
     $buffer = new \IO\Util\Buffer();
     $buffer->registerConsumer(function ($_data) use($flushContainer) {
         $flushContainer->data = $_data;
     });
     $buffer->append("TimeMachine");
     TimeMachine::fastForward(4);
     //fast forward time by 4 seconds
     $buffer->append("rocks");
     TimeMachine::fastForward(7);
     //fast forward time by 7 seconds
     $buffer->append("the world!");
     //since we forwarded time more than 10 seconds our consumer should now have been called,
     //lets check this
     $this->assertEquals(3, count($flushContainer->data));
     $this->assertEquals("TimeMachine", $flushContainer->data[0]);
     $this->assertEquals("rocks", $flushContainer->data[1]);
     $this->assertEquals("the world!", $flushContainer->data[2]);
 }
Beispiel #2
0
 function testBasics()
 {
     $now = "2028-08-29 17:28:49";
     TimeMachine::setNow($now);
     $this->assertEquals($now, date("Y-m-d H:i:s"));
     sleep(1);
     $this->assertEquals("2028-08-29 17:28:50", date("Y-m-d H:i:s"));
     TimeMachine::freeze();
     sleep(1);
     $this->assertEquals("2028-08-29 17:28:50", date("Y-m-d H:i:s"));
     TimeMachine::fastForward(10);
     $this->assertEquals("2028-08-29 17:29:00", date("Y-m-d H:i:s"));
 }