2
0

ValueTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_Memory
  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. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../TestHelper.php';
  26. /** Zend_Memory */
  27. require_once 'Zend/Memory.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_Memory
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Memory_Container_Movable_Dummy extends Zend_Memory_Container_Movable
  36. {
  37. /**
  38. * Dummy object constructor
  39. */
  40. public function __construct()
  41. {
  42. // Do nothing
  43. }
  44. /**
  45. * Dummy value update callback method
  46. */
  47. public function processUpdate()
  48. {
  49. // Do nothing
  50. }
  51. }
  52. /**
  53. * @category Zend
  54. * @package Zend_Memory
  55. * @subpackage UnitTests
  56. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  57. * @license http://framework.zend.com/license/new-bsd New BSD License
  58. * @group Zend_Memory
  59. */
  60. class Zend_Memory_ValueTest extends PHPUnit_Framework_TestCase
  61. {
  62. /**
  63. * tests the Value object creation
  64. */
  65. public function testCreation()
  66. {
  67. $valueObject = new Zend_Memory_Value('data data data ...', new Zend_Memory_Container_Movable_Dummy());
  68. $this->assertTrue($valueObject instanceof Zend_Memory_Value);
  69. $this->assertEquals($valueObject->getRef(), 'data data data ...');
  70. }
  71. /**
  72. * tests the value reference retrieval
  73. */
  74. public function testGetRef()
  75. {
  76. $valueObject = new Zend_Memory_Value('0123456789', new Zend_Memory_Container_Movable_Dummy());
  77. $valueRef = &$valueObject->getRef();
  78. $valueRef[3] = '_';
  79. $this->assertEquals($valueObject->getRef(), '012_456789');
  80. }
  81. /**
  82. * tests the __toString() functionality
  83. */
  84. public function testToString()
  85. {
  86. $valueObject = new Zend_Memory_Value('0123456789', new Zend_Memory_Container_Movable_Dummy());
  87. $this->assertEquals($valueObject->__toString(), '0123456789');
  88. if (version_compare(PHP_VERSION, '5.2') < 0) {
  89. // Skip following tests for PHP versions before 5.2
  90. return;
  91. }
  92. $this->assertEquals(strlen($valueObject), 10);
  93. $this->assertEquals((string)$valueObject, '0123456789');
  94. }
  95. /**
  96. * tests the access through ArrayAccess methods
  97. */
  98. public function testArrayAccess()
  99. {
  100. if (version_compare(PHP_VERSION, '5.2') < 0) {
  101. // Skip following tests for PHP versions before 5.2
  102. return;
  103. }
  104. $valueObject = new Zend_Memory_Value('0123456789', new Zend_Memory_Container_Movable_Dummy());
  105. $this->assertEquals($valueObject[8], '8');
  106. $valueObject[2] = '_';
  107. $this->assertEquals((string)$valueObject, '01_3456789');
  108. $error_level = error_reporting();
  109. error_reporting($error_level & ~E_NOTICE);
  110. $valueObject[10] = '_';
  111. $this->assertEquals((string)$valueObject, '01_3456789_');
  112. error_reporting($error_level);
  113. }
  114. }