BinaryStreamTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. if (!defined('PHPUnit_MAIN_METHOD')) {
  3. define('PHPUnit_MAIN_METHOD', 'Zend_Amf_Util_BinaryStreamTest::main');
  4. }
  5. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  6. require_once 'Zend/Amf/Util/BinaryStream.php';
  7. /**
  8. * Test case for Zend_Amf_Util_BinaryStream
  9. *
  10. * @package Zend_Amf
  11. * @subpackage UnitTests
  12. * @version $Id$
  13. */
  14. class Zend_Amf_Util_BinaryStreamTest extends PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * Runs the test methods of this class.
  18. *
  19. * @return void
  20. */
  21. public static function main()
  22. {
  23. $suite = new PHPUnit_Framework_TestSuite("Zend_Amf_Util_BinaryStreamTest");
  24. $result = PHPUnit_TextUI_TestRunner::run($suite);
  25. }
  26. /**
  27. * @expectedException Zend_Amf_Exception
  28. */
  29. public function testConstructorShouldThrowExceptionForInvalidStream()
  30. {
  31. $test = new Zend_Amf_Util_BinaryStream(array('foo', 'bar'));
  32. }
  33. /**
  34. * @expectedException Zend_Amf_Exception
  35. */
  36. public function testReadBytesShouldRaiseExceptionForBufferUnderrun()
  37. {
  38. $string = 'this is a short stream';
  39. $stream = new Zend_Amf_Util_BinaryStream($string);
  40. $length = strlen($string);
  41. $test = $stream->readBytes(10 * $length);
  42. }
  43. public function testReadBytesShouldReturnSubsetOfStringFromCurrentNeedle()
  44. {
  45. $string = 'this is a short stream';
  46. $stream = new Zend_Amf_Util_BinaryStream($string);
  47. $test = $stream->readBytes(4);
  48. $this->assertEquals('this', $test);
  49. $test = $stream->readBytes(5);
  50. $this->assertEquals(' is a', $test);
  51. }
  52. public function testBinaryStreamsShouldAllowWritingUtf8()
  53. {
  54. $string = str_repeat('赵勇', 1000);
  55. $stream = new Zend_Amf_Util_BinaryStream('');
  56. $stream->writeLongUtf($string);
  57. $test = $stream->getStream();
  58. $this->assertContains($string, $test);
  59. }
  60. }
  61. if (PHPUnit_MAIN_METHOD == 'Zend_Amf_Util_BinaryStreamTest::main') {
  62. Zend_Amf_Util_BinaryStreamTest::main();
  63. }