2
0

FrameTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /*
  23. * The adapter test class provides a universal test class for all of the
  24. * abstract methods.
  25. *
  26. * All methods marked not supported are explictly checked for for throwing
  27. * an exception.
  28. */
  29. /** PHPUnit Test Case */
  30. require_once 'PHPUnit/Framework/TestCase.php';
  31. /** TestHelp.php */
  32. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  33. /** Zend/Queue/Stomp/Frame.php */
  34. require_once 'Zend/Queue/Stomp/Frame.php';
  35. /**
  36. * @category Zend
  37. * @package Zend_Queue
  38. * @subpackage UnitTests
  39. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  40. * @license http://framework.zend.com/license/new-bsd New BSD License
  41. * @group Zend_Queue
  42. */
  43. class Zend_Queue_Stomp_FrameTest extends PHPUnit_Framework_TestCase
  44. {
  45. protected $body = 'hello world'; // 11 characters
  46. public function test_to_fromFrame()
  47. {
  48. $correct = 'SEND' . Zend_Queue_Stomp_Frame::EOL;
  49. $correct .= 'content-length: 11' . Zend_Queue_Stomp_Frame::EOL;
  50. $correct .= Zend_Queue_Stomp_Frame::EOL;
  51. $correct .= $this->body;
  52. $correct .= Zend_Queue_Stomp_Frame::END_OF_FRAME;
  53. $frame = new Zend_Queue_Stomp_Frame();
  54. $frame->setCommand('SEND');
  55. $frame->setBody($this->body);
  56. $this->assertEquals($frame->toFrame(), $correct);
  57. $frame = new Zend_Queue_Stomp_Frame();
  58. $frame->fromFrame($correct);
  59. $this->assertEquals($frame->getCommand(), 'SEND');
  60. $this->assertEquals($frame->getBody(), $this->body);
  61. $this->assertEquals($frame->toFrame(), "$frame");
  62. // fromFrame, but no body
  63. $correct = 'SEND' . Zend_Queue_Stomp_Frame::EOL;
  64. $correct .= 'testing: 11' . Zend_Queue_Stomp_Frame::EOL;
  65. $correct .= Zend_Queue_Stomp_Frame::EOL;
  66. $correct .= Zend_Queue_Stomp_Frame::END_OF_FRAME;
  67. $frame->fromFrame($correct);
  68. $this->assertEquals($frame->getHeader('testing'), 11);
  69. }
  70. public function test_setHeaders()
  71. {
  72. $frame = new Zend_Queue_Stomp_Frame();
  73. $frame->setHeaders(array('testing' => 1));
  74. $this->assertEquals(1, $frame->getHeader('testing'));
  75. }
  76. public function test_parameters()
  77. {
  78. $frame = new Zend_Queue_Stomp_Frame();
  79. try {
  80. $frame->setAutoContentLength(array());
  81. $this->fail('Exception should have been thrown');
  82. } catch(Exception $e) {
  83. $this->assertTrue(true);
  84. }
  85. try {
  86. $frame->setHeader(array(), 1);
  87. $this->fail('Exception should have been thrown');
  88. } catch(Exception $e) {
  89. $this->assertTrue(true);
  90. }
  91. try {
  92. $frame->setHeader('testing', array());
  93. $this->fail('Exception should have been thrown');
  94. } catch(Exception $e) {
  95. $this->assertTrue(true);
  96. }
  97. try {
  98. $frame->getHeader(array());
  99. $this->fail('Exception should have been thrown');
  100. } catch(Exception $e) {
  101. $this->assertTrue(true);
  102. }
  103. try {
  104. $frame->setBody(array());
  105. $this->fail('Exception should have been thrown');
  106. } catch(Exception $e) {
  107. $this->assertTrue(true);
  108. }
  109. try {
  110. $frame->setCommand(array());
  111. $this->fail('Exception should have been thrown');
  112. } catch(Exception $e) {
  113. $this->assertTrue(true);
  114. }
  115. try {
  116. $frame->toFrame();
  117. $this->fail('Exception should have been thrown');
  118. } catch(Exception $e) {
  119. $this->assertTrue(true);
  120. }
  121. try {
  122. $frame->fromFrame(array());
  123. $this->fail('Exception should have been thrown');
  124. } catch(Exception $e) {
  125. $this->assertTrue(true);
  126. }
  127. }
  128. public function test_constant()
  129. {
  130. $this->assertTrue(is_string(Zend_Queue_Stomp_Frame::END_OF_FRAME));
  131. $this->assertTrue(is_string(Zend_Queue_Stomp_Frame::CONTENT_LENGTH));
  132. $this->assertTrue(is_string(Zend_Queue_Stomp_Frame::EOL));
  133. }
  134. }