_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:----pQaSC0X2Kb24AtJwfdLbC7D4eSh7MZC55IRWjOBskM7ZKsVrIu5jlX3fZhE3Yb82KFSK0GMUIQqFapzB233/B4JbpIBh2saT1sOGP9WxWJQ3+kAmgTpT4TaeWLcYxNK6CT/BThm7kOgMqxSHn+IuKsPU9ZgFyfmN/7PB0WD0MRgH4+etKxsm3U+vP+Zz8N9KdrIPn+dRzYJ1F3ck72WkKtK9gnN8cZEa3rdlo8sCx/RBx4UjePIsgcEZR+ORtJ+f4443k/PJ6n9I5P3Pw96URooso6qr+U8n7L5dA8oIUM06kqNYBtw5oLbSvU9SancWFzX5Ds+utZwk1qzTsFckTDhjzBuqOCIkVz4kzjOZJPV+2YSDvBV9RYdZmTlj0AzK0yQj0rPbtj0uNmZihIUNs/EL6/692V7lieoZMUCuz4ClABKBM5wuMUf+qjRCYtmfClejVdRoxseWjtNFtEFujgQDeyE+Gwcuut5jau1uJSMlAZCnSyFaSMvgDEYNgLM4wv0ct6fNaEk15p0btB/1wQS96ZNz3qlFWdbjWWltixPkSpKgq41ILXmvI20aK5FkzRREY6435mI/DgOXjb2TjDT3NKuqstvaWeqWs8sA1FFF5g4deCAGvcmpaIN3dE/YGMm4gV9GYYYH++7cE7u7O+mUdN5q54BlxlEbP/ISvp8=----ATTACHMENT:----OTUzMzM5OTgxOTA0MzM2MSAyODY3MTkwMjU1MTIwNDk1IDM3NTY2OTI3OTQ0NTk2MzE=