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.
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
26 require_once dirname(__FILE__
) . '/../../TestHelper.php';
29 require_once 'Zend/Memory.php';
33 * @package Zend_Memory
34 * @subpackage UnitTests
35 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
36 * @license http://framework.zend.com/license/new-bsd New BSD License
38 class Zend_Memory_Container_Movable_Dummy
extends Zend_Memory_Container_Movable
41 * Dummy object constructor
43 public function __construct()
49 * Dummy value update callback method
51 public function processUpdate()
60 * @package Zend_Memory
61 * @subpackage UnitTests
62 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
63 * @license http://framework.zend.com/license/new-bsd New BSD License
66 class Zend_Memory_ValueTest
extends PHPUnit_Framework_TestCase
69 * tests the Value object creation
71 public function testCreation()
73 $valueObject = new Zend_Memory_Value('data data data ...', new Zend_Memory_Container_Movable_Dummy());
74 $this->assertTrue($valueObject instanceof Zend_Memory_Value
);
75 $this->assertEquals($valueObject->getRef(), 'data data data ...');
80 * tests the value reference retrieval
82 public function testGetRef()
84 $valueObject = new Zend_Memory_Value('0123456789', new Zend_Memory_Container_Movable_Dummy());
85 $valueRef = &$valueObject->getRef();
88 $this->assertEquals($valueObject->getRef(), '012_456789');
93 * tests the __toString() functionality
95 public function testToString()
97 $valueObject = new Zend_Memory_Value('0123456789', new Zend_Memory_Container_Movable_Dummy());
98 $this->assertEquals($valueObject->__toString(), '0123456789');
100 if (version_compare(PHP_VERSION
, '5.2') < 0) {
101 // Skip following tests for PHP versions before 5.2
105 $this->assertEquals(strlen($valueObject), 10);
106 $this->assertEquals((string)$valueObject, '0123456789');
110 * tests the access through ArrayAccess methods
112 public function testArrayAccess()
114 if (version_compare(PHP_VERSION
, '5.2') < 0) {
115 // Skip following tests for PHP versions before 5.2
119 $valueObject = new Zend_Memory_Value('0123456789', new Zend_Memory_Container_Movable_Dummy());
120 $this->assertEquals($valueObject[8], '8');
122 $valueObject[2] = '_';
123 $this->assertEquals((string)$valueObject, '01_3456789');
126 $error_level = error_reporting();
127 error_reporting($error_level & ~E_NOTICE
);
128 $valueObject[10] = '_';
129 $this->assertEquals((string)$valueObject, '01_3456789_');
130 error_reporting($error_level);