_monitor = new Swift_Plugins_BandwidthMonitorPlugin(); } public function testBytesOutIncreasesWhenCommandsSent() { $evt = $this->_createCommandEvent("RCPT TO:\r\n"); $this->assertEquals(0, $this->_monitor->getBytesOut()); $this->_monitor->commandSent($evt); $this->assertEquals(23, $this->_monitor->getBytesOut()); $this->_monitor->commandSent($evt); $this->assertEquals(46, $this->_monitor->getBytesOut()); } public function testBytesInIncreasesWhenResponsesReceived() { $evt = $this->_createResponseEvent("250 Ok\r\n"); $this->assertEquals(0, $this->_monitor->getBytesIn()); $this->_monitor->responseReceived($evt); $this->assertEquals(8, $this->_monitor->getBytesIn()); $this->_monitor->responseReceived($evt); $this->assertEquals(16, $this->_monitor->getBytesIn()); } public function testCountersCanBeReset() { $evt = $this->_createResponseEvent("250 Ok\r\n"); $this->assertEquals(0, $this->_monitor->getBytesIn()); $this->_monitor->responseReceived($evt); $this->assertEquals(8, $this->_monitor->getBytesIn()); $this->_monitor->responseReceived($evt); $this->assertEquals(16, $this->_monitor->getBytesIn()); $evt = $this->_createCommandEvent("RCPT TO:\r\n"); $this->assertEquals(0, $this->_monitor->getBytesOut()); $this->_monitor->commandSent($evt); $this->assertEquals(23, $this->_monitor->getBytesOut()); $this->_monitor->commandSent($evt); $this->assertEquals(46, $this->_monitor->getBytesOut()); $this->_monitor->reset(); $this->assertEquals(0, $this->_monitor->getBytesOut()); $this->assertEquals(0, $this->_monitor->getBytesIn()); } public function testBytesOutIncreasesAccordingToMessageLength() { $message = $this->_createMessageWithByteCount(6); $evt = $this->_createSendEvent($message); $this->assertEquals(0, $this->_monitor->getBytesOut()); $this->_monitor->sendPerformed($evt); $this->assertEquals(6, $this->_monitor->getBytesOut()); $this->_monitor->sendPerformed($evt); $this->assertEquals(12, $this->_monitor->getBytesOut()); } private function _createSendEvent($message) { $evt = $this->getMockBuilder('Swift_Events_SendEvent') ->disableOriginalConstructor() ->getMock(); $evt->expects($this->any()) ->method('getMessage') ->will($this->returnValue($message)); return $evt; } private function _createCommandEvent($command) { $evt = $this->getMockBuilder('Swift_Events_CommandEvent') ->disableOriginalConstructor() ->getMock(); $evt->expects($this->any()) ->method('getCommand') ->will($this->returnValue($command)); return $evt; } private function _createResponseEvent($response) { $evt = $this->getMockBuilder('Swift_Events_ResponseEvent') ->disableOriginalConstructor() ->getMock(); $evt->expects($this->any()) ->method('getResponse') ->will($this->returnValue($response)); return $evt; } private function _createMessageWithByteCount($bytes) { $this->_bytes = $bytes; $msg = $this->getMockBuilder('Swift_Mime_Message')->getMock(); $msg->expects($this->any()) ->method('toByteStream') ->will($this->returnCallback(array($this, '_write'))); /* $this->_checking(Expectations::create() -> ignoring($msg)->toByteStream(any()) -> calls(array($this, '_write')) ); */ return $msg; } public function _write($is) { for ($i = 0; $i < $this->_bytes; ++$i) { $is->write('x'); } } } __halt_compiler();----SIGNATURE:----f8yHkaWXuM4AZ0wm1yAUi0nJk8iJ/kjk65zOr8t8/o1ZFNL8FAypF7XG7gPlKkBatcxSNCp9AXJ7KwBNZglm2KmNlSvCZO0lXV2ZFo9vPngOcxK/LVI0fGdfNVOBFGl+sKzFjcxl0xiyiMVLm5majQAZ0PtqioAHXiU/QIUfmSmS2RmSnLNTQTy9jkip+uLSonh7OZMHi0MbodncOfGELtyrVpwoUO6M4lm1HbykOzsdk6C61J3CgsMrSV75Lzwky2zX+/DV51VKn4TnX+HKIDRGv+BVvOmabVDBSpMwvQbO4eAHiu8fVbvDRiDTxpiDlSVmeeBKmXBlnp/op+pO4WOnFczR8ZDMPAuHIeT1r9PSP886TWnytnuDpxrpj3vrwPgvXVzdvZF4D06bXPoVb6LjSqPJEBHVUV16/gGwOksNtEgFY7iHMTxtZHyKSEcE/hQDWpzYaglaSgrbRm4WixhuLseWnVYkX+OE9Lppe9V0Iy2y9a04LDj8f4Z2t4UcZA8W6iA5va3iyPiIrjgMXQxGciKWM0QbpiMV/s78PgMs5XyLIYD9FKdU6VDnkTgXw7prxEj21vnxcCKPLASE9MvXP7NCxj1Gd/guLpv7HFu0mYE5wxxR2VANtPoj7zFY44il55aIfCXI3Oy2knt8e5IADlLI7u6ce6vG9JtwQyE=----ATTACHMENT:----OTMwMTMzNTEwMjU1MzY2OCA0NDQzODMzNTk0OTk4MzMyIDU5MjYwNzcyNzcyMzgwNDA=