ValueTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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-2008 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-2008 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. * @package Zend_Memory
  54. * @subpackage UnitTests
  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. $valueObject[10] = '_';
  105. $this->assertEquals((string)$valueObject, '01_3456789_');
  106. }
  107. }