/**
  * @test
  * @expectedException \RuntimeException
  */
 public function it_should_compose_empty_message_without_auth()
 {
     $this->socketMessage = $this->socketMessage->reveal();
     $binaryMessage = $this->messageComposer->compose($this->socketMessage);
     $buffer = new Buffer($binaryMessage);
     \PHPUnit_Framework_Assert::assertEquals(18, $buffer->readInt32LE(0));
     \PHPUnit_Framework_TestCase::assertEquals(MessageType::HEARTBEAT_REQUEST, $buffer->readInt8(4));
     \PHPUnit_Framework_TestCase::assertEquals(MessageConfiguration::FLAGS_NONE, $buffer->readInt8(5));
     \PHPUnit_Framework_TestCase::assertEquals('12350000000000000000000000000000', bin2hex($buffer->read(6, 16)));
     //should throw exception out of range
     $buffer->read(22, 1);
 }
 /**
  * @test
  */
 public function it_should_send_message()
 {
     $this->socketMessage = $this->socketMessage->reveal();
     $this->messageComposer->compose($this->socketMessage)->willReturn('binary');
     $this->stream->write('binary')->shouldBeCalledTimes(1);
     $this->streamHandler->sendMessage($this->socketMessage);
 }
 /**
  * Sends message to stream sever
  *
  * @param SocketMessage $socketMessage
  *
  * @return void
  * @throws DomainException
  */
 public function sendMessage(SocketMessage $socketMessage)
 {
     try {
         $binaryMessage = $this->messageComposer->compose($socketMessage);
         $this->stream->write($binaryMessage);
     } catch (\Exception $e) {
         $this->logger->critical('Error during send a message with ' . $socketMessage->getMessageType()->getType() . ' and id ' . $socketMessage->getCorrelationID() . '. Message Error: ' . $e->getMessage());
     }
 }