IgbinaryTest.php 4.6 KB

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