ValueTest.php 3.6 KB

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