public function testWriteWithMock()
 {
     $this->setMockHandler(array('fwrite'));
     $callback = function ($arg) {
         $map = array('Hello world' => 6, 'world' => 5);
         return $map[$arg];
     };
     $this->handler->expects($this->exactly(2))->method('fwrite')->will($this->returnCallback($callback));
     $this->writeRecord('Hello world');
 }
 private function setMockHandler(array $methods = array())
 {
     $this->res = fopen('php://memory', 'a');
     $defaultMethods = array('fsockopen', 'pfsockopen', 'streamSetTimeout');
     $newMethods = array_diff($methods, $defaultMethods);
     $finalMethods = array_merge($defaultMethods, $newMethods);
     $this->handler = $this->getMock('\\Monolog\\Handler\\SocketHandler', $finalMethods, array('localhost:1234'));
     if (!in_array('fsockopen', $methods)) {
         $this->handler->expects($this->any())->method('fsockopen')->will($this->returnValue($this->res));
     }
     if (!in_array('pfsockopen', $methods)) {
         $this->handler->expects($this->any())->method('pfsockopen')->will($this->returnValue($this->res));
     }
     if (!in_array('streamSetTimeout', $methods)) {
         $this->handler->expects($this->any())->method('streamSetTimeout')->will($this->returnValue(true));
     }
     $this->handler->setFormatter($this->getIdentityFormatter());
 }