| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Queue
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- /*
- * The adapter test class provides a universal test class for all of the
- * abstract methods.
- *
- * All methods marked not supported are explictly checked for for throwing
- * an exception.
- */
- /** Zend_Queue_Stomp_Frame */
- require_once 'Zend/Queue/Stomp/Frame.php';
- /** Zend_Queue_Stomp_Client */
- require_once 'Zend/Queue/Stomp/Client.php';
- /** Zend_Queue_Stomp_Client_Interface */
- require_once 'Zend/Queue/Stomp/Client/Connection.php';
- /**
- * @category Zend
- * @package Zend_Queue
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Queue
- */
- class Zend_Queue_Stomp_Connection_Mock
- extends Zend_Queue_Stomp_Client_Connection
- {
- /**
- * open() opens a socket to the Stomp server
- *
- * @param array $config ('scheme', 'host', 'port')
- * @return true;
- */
- public function open($scheme, $host, $port)
- {
- if ( $port == 0 ) return false;
- return true;
- }
- public function close($destructor = false)
- {
- }
- /**
- * Check whether we are connected to the server
- *
- * @return true
- * @throws Zend_Queue_Exception
- */
- public function ping()
- {
- return true;
- }
- /**
- * write a frame to the stomp server
- *
- * @example $response = $client->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);
- }
- }
- /**
- * @category Zend
- * @package Zend_Queue
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Queue
- */
- 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());
- }
- }
|