| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/core/src/lmbSerializable.class.php'); 10 lmb_require(dirname(__FILE__) . '/serializable_stubs.inc.php'); 11 12 class lmbSerializableTest extends UnitTestCase 13 { 14 function testCheckClassPaths() 15 { 16 $stub = new SerializableTestStub(); 17 $stub->again = new SerializableTestStub(); 18 19 $container = new lmbSerializable($stub); 20 21 $this->assertEqual($container->getClassPaths(), array()); 22 23 $serialized = serialize($container); 24 25 $this->assertEqual($container->getClassPaths(), array($this->_getClassPath('SerializableTestStub'), 26 $this->_getClassPath('SerializableTestChildStub'))); 27 } 28 29 function testSerializeUnserialize() 30 { 31 $stub = new SerializableTestStub(); 32 $container = new lmbSerializable($stub); 33 34 $file = $this->_writeToFile(serialize($container)); 35 $this->_phpSerializedObjectCall($file, '->identify()', $stub); 36 $this->_phpSerializedObjectCall($file, '->getChild()->identify()', $stub->getChild()->identify()); 37 unlink($file); 38 } 39 40 function testSerializeUnserializeWithoutSubjectLazyLoading() 41 { 42 $stub = new SerializableTestStub(); 43 $container1 = new lmbSerializable($stub); 44 45 $file1 = $this->_writeToFile(serialize($container1)); 46 $container2 = unserialize(file_get_contents($file1)); 47 48 $file2 = $this->_writeToFile(serialize($container2)); 49 $this->_phpSerializedObjectCall($file2, '->identify()', $stub); 50 $this->_phpSerializedObjectCall($file2, '->getChild()->identify()', $stub->getChild()->identify()); 51 52 unlink($file1); 53 unlink($file2); 54 } 55 56 function testExtractSerializedClasses() 57 { 58 $stub = new SerializableTestChildStub(); 59 $serialized = serialize($stub); 60 $this->assertEqual(lmbSerializable :: extractSerializedClasses($serialized), array('SerializableTestChildStub')); 61 } 62 63 function _writeToFile($serialized) 64 { 65 $tmp_serialized_file = LIMB_VAR_DIR . '/serialized.' . mt_rand(); 66 file_put_contents($tmp_serialized_file, $serialized); 67 return $tmp_serialized_file; 68 } 69 70 function _phpSerializedObjectCall($file, $call) 71 { 72 $class_path = $this->_getClassPath('lmbSerializable'); 73 74 $cmd = "php -r \"require_once('$class_path');" . 75 "echo unserialize(file_get_contents('$file'))->getSubject()$call;\""; 76 77 exec($cmd, $ret, $out); 78 return $out; 79 } 80 81 function _getClassPath($class) 82 { 83 $ref = new ReflectionClass($class); 84 return $ref->getFileName(); 85 } 86 } 87 88 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Aug 29 04:49:26 2008 | Cross-referenced by PHPXref 0.7 |