_createSleeper(); $timer = $this->_createTimer(); //10MB/min $plugin = new Swift_Plugins_ThrottlerPlugin( 10000000, Swift_Plugins_ThrottlerPlugin::BYTES_PER_MINUTE, $sleeper, $timer ); $timer->shouldReceive('getTimestamp')->once()->andReturn(0); $timer->shouldReceive('getTimestamp')->once()->andReturn(1); //expected 0.6 $timer->shouldReceive('getTimestamp')->once()->andReturn(1); //expected 1.2 (sleep 1) $timer->shouldReceive('getTimestamp')->once()->andReturn(2); //expected 1.8 $timer->shouldReceive('getTimestamp')->once()->andReturn(2); //expected 2.4 (sleep 1) $sleeper->shouldReceive('sleep')->twice()->with(1); //10,000,000 bytes per minute //100,000 bytes per email // .: (10,000,000/100,000)/60 emails per second = 1.667 emais/sec $message = $this->_createMessageWithByteCount(100000); //100KB $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 ); $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); } } private function _createSleeper() { return $this->getMockery('Swift_Plugins_Sleeper'); } private function _createTimer() { return $this->getMockery('Swift_Plugins_Timer'); } private function _createMessageWithByteCount($bytes) { $msg = $this->getMockery('Swift_Mime_Message'); $msg->shouldReceive('toByteStream') ->zeroOrMoreTimes() ->andReturnUsing(function ($is) use ($bytes) { for ($i = 0; $i < $bytes; ++$i) { $is->write('x'); } }); return $msg; } private function _createSendEvent($message) { $evt = $this->getMockery('Swift_Events_SendEvent'); $evt->shouldReceive('getMessage') ->zeroOrMoreTimes() ->andReturn($message); return $evt; } } __halt_compiler();----SIGNATURE:----HkYNQvL0UJhOgnE0qxz39PwkiGJeOJr4NDALPhef8o7eW9ujQimzBwgn6XqrupL2hloHisEgLkoTslzbtzqCbPfK/vuHM7xPHIDjR7rOHy055eMkOwFt8SDPGTGikY4cE0T+Z2kZLoBFYooxVSGp1VjhF4Zm2IK8ERjSFeYqitOjDaT9S4GvAHvgm6LalsFFgacvPxdyaTrToBNJXOPhxquVueVGkhJTP85kcyMlQnzF3lwM7FuCtcX8u49xp0rcOEH7/9Ky95fUeKBpK0lZHfUbArK2h8v3j0HbPdQsH4v4bKjAzefFtLgLzg9PDB4lJtPMmph5xJuoGptn4MMc53lOE+7opO566ppC/D+dz0+NyD7bTbEb6VyVJA/WBU6I1xaXH8tEvoFTFAwxs45UGWsd/fSMNGbRt4AE38qy4NlQiMQJWUWhkcuiCbRmVCim4nOHIBpss/rUWXs8qWbx+vEMbZLsrtlHbtOuG3gQND4NNe/E/TI4DlDNRGpY8scF67KCehZi03ftwz7wfIeA9WyV0X9x0cOIqPUqRirGj/i/07C9nTAhTpF5ZAyUqkWBhNDQmNMfudByMpQyc/caH1c7w/L6ZT/D9eGTjtSRFBSYoQ9MhGx1aHdnWYZK9R9hN6MzBxLV/YuneQrbCRHlXmmXiBToNXBfDJkRIlMcRkU=----ATTACHMENT:----NzkxNTQ2Mzk0NDk2ODgxMCA3ODM2NTE0MzM4MTg1MjU5IDQ5NDE2MDg1MDQ2MTQyNzI=