Author: Chris Corbyn
Inheritance: extends Swift_Plugins_BandwidthMonitorPlugin, implements Swift_Plugins_Sleeper, implements Swift_Plugins_Timer
 public function testMessagesPerMinuteThrottling()
 {
     $sleeper = $this->_createSleeper();
     $timer = $this->_createTimer();
     //60/min
     $plugin = new Swift_Plugins_ThrottlerPlugin(60, Swift_Plugins_ThrottlerPlugin::MESSAGES_PER_MINUTE, $sleeper, $timer);
     $timer->shouldReceive('getTimestamp')->once()->andReturn(0);
     $timer->shouldReceive('getTimestamp')->once()->andReturn(0);
     //expected 1 (sleep 1)
     $timer->shouldReceive('getTimestamp')->once()->andReturn(2);
     //expected 2
     $timer->shouldReceive('getTimestamp')->once()->andReturn(2);
     //expected 3 (sleep 1)
     $timer->shouldReceive('getTimestamp')->once()->andReturn(4);
     //expected 4
     $sleeper->shouldReceive('sleep')->twice()->with(1);
     //60 messages per minute
     //1 message per second
     $message = $this->_createMessageWithByteCount(10);
     $evt = $this->_createSendEvent($message);
     for ($i = 0; $i < 5; ++$i) {
         $plugin->beforeSendPerformed($evt);
         $plugin->sendPerformed($evt);
     }
 }
 public function testMessagesPerMinuteThrottling()
 {
     $sleeper = $this->_createSleeper();
     $timer = $this->_createTimer();
     //60/min
     $plugin = new Swift_Plugins_ThrottlerPlugin(60, Swift_Plugins_ThrottlerPlugin::MESSAGES_PER_MINUTE, $sleeper, $timer);
     $this->_checking(Expectations::create()->one($timer)->getTimestamp()->returns(0)->one($timer)->getTimestamp()->returns(0)->one($timer)->getTimestamp()->returns(2)->one($timer)->getTimestamp()->returns(2)->one($timer)->getTimestamp()->returns(4)->ignoring($timer)->exactly(2)->of($sleeper)->sleep(1));
     //60 messages per minute
     //1 message per second
     $message = $this->_createMessageWithByteCount(10);
     $evt = $this->_createSendEvent($message);
     for ($i = 0; $i < 5; ++$i) {
         $plugin->beforeSendPerformed($evt);
         $plugin->sendPerformed($evt);
     }
 }