IgbinaryTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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_Serializer
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 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. * @see Zend_Serializer_Adapter_Igbinary
  24. */
  25. require_once 'Zend/Serializer/Adapter/Igbinary.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Serializer
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Serializer_Adapter_IgbinaryTest extends PHPUnit_Framework_TestCase
  34. {
  35. private $_adapter;
  36. public function setUp()
  37. {
  38. $this->_adapter = new Zend_Serializer_Adapter_Igbinary();
  39. }
  40. public function tearDown()
  41. {
  42. $this->_adapter = null;
  43. }
  44. public function testSerializeString()
  45. {
  46. $value = 'test';
  47. $expected = igbinary_serialize($value);
  48. $data = $this->_adapter->serialize($value);
  49. $this->assertEquals($expected, $data);
  50. }
  51. public function testSerializeFalse()
  52. {
  53. $value = false;
  54. $expected = igbinary_serialize($value);
  55. $data = $this->_adapter->serialize($value);
  56. $this->assertEquals($expected, $data);
  57. }
  58. public function testSerializeNull()
  59. {
  60. $value = null;
  61. $expected = igbinary_serialize($value);
  62. $data = $this->_adapter->serialize($value);
  63. $this->assertEquals($expected, $data);
  64. }
  65. public function testSerializeNumeric()
  66. {
  67. $value = 100;
  68. $expected = igbinary_serialize($value);
  69. $data = $this->_adapter->serialize($value);
  70. $this->assertEquals($expected, $data);
  71. }
  72. public function testSerializeObject()
  73. {
  74. $value = new stdClass();
  75. $expected = igbinary_serialize($value);
  76. $data = $this->_adapter->serialize($value);
  77. $this->assertEquals($expected, $data);
  78. }
  79. public function testUnserializeString()
  80. {
  81. $expected = 'test';
  82. $value = igbinary_serialize($expected);
  83. $data = $this->_adapter->unserialize($value);
  84. $this->assertEquals($expected, $data);
  85. }
  86. public function testUnserializeFalse()
  87. {
  88. $expected = false;
  89. $value = igbinary_serialize($expected);
  90. $data = $this->_adapter->unserialize($value);
  91. $this->assertEquals($expected, $data);
  92. }
  93. public function testUnserializeNull()
  94. {
  95. $expected = null;
  96. $value = igbinary_serialize($expected);
  97. $data = $this->_adapter->unserialize($value);
  98. $this->assertEquals($expected, $data);
  99. }
  100. public function testUnserializeNumeric()
  101. {
  102. $expected = 100;
  103. $value = igbinary_serialize($expected);
  104. $data = $this->_adapter->unserialize($value);
  105. $this->assertEquals($expected, $data);
  106. }
  107. public function testUnserializeObject()
  108. {
  109. $expected = new stdClass();
  110. $value = igbinary_serialize($expected);
  111. $data = $this->_adapter->unserialize($value);
  112. $this->assertEquals($expected, $data);
  113. }
  114. public function testUnserialzeInvalid()
  115. {
  116. $value = "\0\1\r\n";
  117. $this->setExpectedException('Zend_Serializer_Exception');
  118. $this->_adapter->unserialize($value);
  119. }
  120. }
  121. /**
  122. * @category Zend
  123. * @package Zend_Serializer
  124. * @subpackage UnitTests
  125. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  126. * @license http://framework.zend.com/license/new-bsd New BSD License
  127. */
  128. class Zend_Serializer_Adapter_IgbinarySkipTest extends PHPUnit_Framework_TestCase
  129. {
  130. public $message = null;
  131. public function setUp()
  132. {
  133. $message = 'Skipped Zend_Serializer_Adapter_IgbinaryTest';
  134. if ($this->message) {
  135. $message.= ': ' . $this->message;
  136. }
  137. $this->markTestSkipped($message);
  138. }
  139. public function testEmpty()
  140. {
  141. // this is here only so we have at least one test
  142. }
  143. }