ActivemqOfflineTest.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Queue
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: ActivemqTest.php 20096 2010-01-06 02:05:09Z bkarwin $
  21. */
  22. require_once 'Zend/Queue/Adapter/Activemq.php';
  23. require_once 'Zend/Queue/Stomp/Client.php';
  24. require_once 'Zend/Queue/Stomp/Frame.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Queue
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @group Zend_Queue
  32. */
  33. class Zend_Queue_Adapter_ActivemqOfflineTest extends PHPUnit_Framework_TestCase
  34. {
  35. /**
  36. * @group ZF-7948
  37. */
  38. public function testSubscribesOncePerQueue()
  39. {
  40. $stompClient = new StompClientMock;
  41. $options['driverOptions']['stompClient'] = $stompClient;
  42. $adapter = new Zend_Queue_Adapter_Activemq($options);
  43. $queue = new Zend_Queue('array', array('name' => 'foo'));
  44. $adapter->receive(null, null, $queue);
  45. $adapter->receive(null, null, $queue);
  46. // iterate through mock StompClient and ensure SUBSCRIBE is only sent once per queue
  47. $subscribes = 0;
  48. foreach ($stompClient->frameStack as $frame) {
  49. if ($frame->getCommand() === 'SUBSCRIBE') {
  50. $subscribes++;
  51. }
  52. }
  53. $this->assertEquals(1, $subscribes);
  54. }
  55. }
  56. class StompClientMock extends Zend_Queue_Stomp_Client
  57. {
  58. public $frameStack = array();
  59. public $responseStack = array();
  60. public function __construct() {
  61. // spoof a successful connection in the response stack
  62. $frame = new Zend_Queue_Stomp_Frame;
  63. $frame->setCommand('CONNECTED');
  64. $this->responseStack[] = $frame;
  65. }
  66. public function __destruct() {}
  67. public function send(Zend_Queue_Stomp_FrameInterface $frame)
  68. {
  69. $this->frameStack[] = $frame;
  70. return $this;
  71. }
  72. public function receive()
  73. {
  74. return array_shift($this->responseStack);
  75. }
  76. public function canRead()
  77. {
  78. return count($this->responseStack) > 0;
  79. }
  80. public function createFrame()
  81. {
  82. return new Zend_Queue_Stomp_Frame;
  83. }
  84. }