write($frame)->read(); * * @param Zend_Queue_Stom_Frame $frame * @return $this */ public function write(Zend_Queue_Stomp_FrameInterface $frame) { $this->_buffer[] = $frame; } /** * tests the socket to see if there is data for us */ public function canRead() { return count($this->_buffer) > 0; } /** * reads in a frame from the socket or returns false. * * @return Zend_Queue_Stomp_Frame|false * @throws Zend_Queue_Exception */ public function read() { if (! $this->canRead()) return false; return array_shift($this->_buffer); } } class Zend_Queue_Stomp_ClientTest extends PHPUnit_Framework_TestCase { public function testConstruct() { $client = new Zend_Queue_Stomp_Client('tcp', 'localhost', '11232', 'Zend_Queue_Stomp_Connection_Mock'); $this->assertTrue($client->getConnection() instanceof Zend_Queue_Stomp_Client_ConnectionInterface); } public function testAddConnection() { $client = new Zend_Queue_Stomp_Client(); $client->addConnection('tcp', 'localhost', '11232', 'Zend_Queue_Stomp_Connection_Mock'); $this->assertTrue($client->getConnection() instanceof Zend_Queue_Stomp_Client_ConnectionInterface); $client = new Zend_Queue_Stomp_Client(); $this->assertFalse($client->addConnection('tcp', 'localhost', 0, 'Zend_Queue_Stomp_Connection_Mock')); } public function testGetAndSetConnection() { $connection = new Zend_Queue_Stomp_Connection_Mock('tcp', 'localhost', '11232'); $client = new Zend_Queue_Stomp_Client(); $this->assertTrue($client->setConnection($connection) instanceof Zend_Queue_Stomp_Client); $try = $client->getConnection(); $this->assertEquals($connection, $try); } public function testSendAndReceive() { $frame = new Zend_Queue_Stomp_Frame(); $frame->setCommand('testing'); $frame->setHeader('testing',1); $frame->setBody('hello world'); $client = new Zend_Queue_Stomp_Client(); $client->addConnection('tcp', 'localhost', '11232', 'Zend_Queue_Stomp_Connection_Mock'); $client->send($frame); $this->assertTrue($client->canRead()); $test = $client->receive(); $this->assertEquals('testing', $test->getCommand()); $this->assertEquals(1, $test->getHeader('testing')); $this->assertEquals('hello world', $test->getBody()); } }