IgbinaryTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * @package Zend_Cache
  4. * @subpackage UnitTests
  5. */
  6. /** @see Zend_Serializer_Adapter_Igbinary */
  7. require_once 'Zend/Serializer/Adapter/Igbinary.php';
  8. /**
  9. * PHPUnit test case
  10. */
  11. require_once 'PHPUnit/Framework/TestCase.php';
  12. /**
  13. * @package Zend_Serializer
  14. * @subpackage UnitTests
  15. */
  16. class Zend_Serializer_Adapter_IgbinaryTest extends PHPUnit_Framework_TestCase
  17. {
  18. private $_adapter;
  19. public function setUp()
  20. {
  21. $this->_adapter = new Zend_Serializer_Adapter_Igbinary();
  22. }
  23. public function tearDown()
  24. {
  25. $this->_adapter = null;
  26. }
  27. public function testSerializeString() {
  28. $value = 'test';
  29. $expected = igbinary_serialize($value);
  30. $data = $this->_adapter->serialize($value);
  31. $this->assertEquals($expected, $data);
  32. }
  33. public function testSerializeFalse() {
  34. $value = false;
  35. $expected = igbinary_serialize($value);
  36. $data = $this->_adapter->serialize($value);
  37. $this->assertEquals($expected, $data);
  38. }
  39. public function testSerializeNull() {
  40. $value = null;
  41. $expected = igbinary_serialize($value);
  42. $data = $this->_adapter->serialize($value);
  43. $this->assertEquals($expected, $data);
  44. }
  45. public function testSerializeNumeric() {
  46. $value = 100;
  47. $expected = igbinary_serialize($value);
  48. $data = $this->_adapter->serialize($value);
  49. $this->assertEquals($expected, $data);
  50. }
  51. public function testSerializeObject() {
  52. $value = new stdClass();
  53. $expected = igbinary_serialize($value);
  54. $data = $this->_adapter->serialize($value);
  55. $this->assertEquals($expected, $data);
  56. }
  57. public function testUnserializeString() {
  58. $expected = 'test';
  59. $value = igbinary_serialize($expected);
  60. $data = $this->_adapter->unserialize($value);
  61. $this->assertEquals($expected, $data);
  62. }
  63. public function testUnserializeFalse() {
  64. $expected = false;
  65. $value = igbinary_serialize($expected);
  66. $data = $this->_adapter->unserialize($value);
  67. $this->assertEquals($expected, $data);
  68. }
  69. public function testUnserializeNull() {
  70. $expected = null;
  71. $value = igbinary_serialize($expected);
  72. $data = $this->_adapter->unserialize($value);
  73. $this->assertEquals($expected, $data);
  74. }
  75. public function testUnserializeNumeric() {
  76. $expected = 100;
  77. $value = igbinary_serialize($expected);
  78. $data = $this->_adapter->unserialize($value);
  79. $this->assertEquals($expected, $data);
  80. }
  81. public function testUnserializeObject() {
  82. $expected = new stdClass();
  83. $value = igbinary_serialize($expected);
  84. $data = $this->_adapter->unserialize($value);
  85. $this->assertEquals($expected, $data);
  86. }
  87. public function testUnserialzeInvalid() {
  88. $value = "\0\1\r\n";
  89. $this->setExpectedException('Zend_Serializer_Exception');
  90. $this->_adapter->unserialize($value);
  91. }
  92. }
  93. /**
  94. * @category Zend
  95. * @package Zend_Serializer
  96. * @subpackage UnitTests
  97. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  98. * @license http://framework.zend.com/license/new-bsd New BSD License
  99. */
  100. class Zend_Serializer_Adapter_IgbinarySkipTest extends PHPUnit_Framework_TestCase
  101. {
  102. public $message = null;
  103. public function setUp()
  104. {
  105. $message = 'Skipped Zend_Serializer_Adapter_IgbinaryTest';
  106. if ($this->message) {
  107. $message.= ': ' . $this->message;
  108. }
  109. $this->markTestSkipped($message);
  110. }
  111. public function testEmpty()
  112. {
  113. // this is here only so we have at least one test
  114. }
  115. }