FrameTest.php 4.5 KB

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