Ejemplo n.º 1
0
 public function testMessagesAreDiscardedAfter20OnTimer()
 {
     //DAO's get_message is called once
     $this->dao->expects($this->exactly(30))->method('get_messages')->will($this->returnValue(array(1 => array('foo'))));
     //DAO's set_active_users is callid once with the expected active users
     $this->dao->expects($this->exactly(30))->method('set_active_users');
     for ($i = 0; $i < 30; $i++) {
         $this->object->on_timer();
         $this->assertEquals(min($i + 1, 20), count($this->object->get_messages(1)));
     }
 }
 /**
  * @dataProvider messagesProvider
  */
 public function testOnTimer($messages, $active_users)
 {
     $dao = $this->getMock('longPollDao');
     //DAO's get_message is called once
     $dao->expects($this->once())->method('get_messages')->will($this->returnValue($messages));
     //DAO's set_active_users is callid once with the expected active users
     $dao->expects($this->once())->method('set_active_users')->with($this->equalTo($active_users));
     $server = new longPollServer('longPollServerClient');
     $server->dao = $dao;
     //For the server, active users are those for which get_messages has been
     //called since last on_timer call.
     foreach ($active_users as $uid) {
         $server->get_messages($uid);
     }
     $server->on_timer();
     foreach ($messages as $uid => $m) {
         $this->assertEquals(isset($m) ? $m : array(), $server->get_messages($uid), 'Messages from DAO are returned by longPollServer::get_messages after longPollServer::on_timer.');
         $server->flush_messages($uid);
         $this->assertEquals(array(), $server->get_messages($uid), 'Messages are not returned after longPollServer::flush_messages.');
     }
 }