示例#1
0
 public function testExtractNextMessage()
 {
     // Make sure the buffer is empty to start
     $this->assertEquals('', $this->stomp->_getBuffer());
     $this->assertFalse($this->stomp->_bufferContainsMessage());
     // Fill the buffer up with 3 messages
     $this->stomp->_appendToBuffer("MESSAGE1\n\nBODY1\n");
     $this->stomp->_appendToBuffer("MESSAGE2\n\nBODY2\n");
     $this->stomp->_appendToBuffer("MESSAGE3\n\nBODY3\n");
     $this->assertEquals("MESSAGE1\n\nBODY1\nMESSAGE2\n\nBODY2\nMESSAGE3\n\nBODY3\n", $this->stomp->_getBuffer());
     $this->assertTrue($this->stomp->_bufferContainsMessage());
     // Extract all 3 sequentially
     $this->assertEquals("MESSAGE1\n\nBODY1\n", $this->stomp->_extractNextMessage());
     $this->assertEquals("MESSAGE2\n\nBODY2\nMESSAGE3\n\nBODY3\n", $this->stomp->_getBuffer());
     $this->assertEquals("MESSAGE2\n\nBODY2\n", $this->stomp->_extractNextMessage());
     $this->assertEquals("MESSAGE3\n\nBODY3\n", $this->stomp->_getBuffer());
     $this->assertEquals("MESSAGE3\n\nBODY3\n", $this->stomp->_extractNextMessage());
     $this->assertEquals("", $this->stomp->_getBuffer());
     // Now that the buffer is empty, add another message
     $this->stomp->_appendToBuffer("MESSAGE4\n\nBODY4\n");
     $this->assertEquals("MESSAGE4\n\nBODY4\n", $this->stomp->_getBuffer());
     // Extract that message
     $this->assertEquals("MESSAGE4\n\nBODY4\n", $this->stomp->_extractNextMessage());
     $this->assertEquals("", $this->stomp->_getBuffer());
     // verify that trying to extract from an empty buffer returns empty string
     $this->stomp->_appendToBuffer("");
     $this->assertEquals("", $this->stomp->_getBuffer());
     // Now that the buffer is empty, add another message
     // This is to verify that extracting a message from an empty buffer doesn't break something
     $this->stomp->_appendToBuffer("MESSAGE5\n\nBODY5\n");
     $this->assertEquals("MESSAGE5\n\nBODY5\n", $this->stomp->_getBuffer());
     // Extract that message
     $this->assertEquals("MESSAGE5\n\nBODY5\n", $this->stomp->_extractNextMessage());
     $this->assertEquals("", $this->stomp->_getBuffer());
     // verify that trying to extract from an empty buffer returns empty string
     $this->stomp->_appendToBuffer("");
     $this->assertEquals("", $this->stomp->_getBuffer());
 }