FrameTest.php 4.6 KB

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