. */ /** * Doctrine_Record_SerializeUnserialize_TestCase * * @package Doctrine * @author Konsta Vesterinen * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @category Object Relational Mapping * @link www.phpdoctrine.com * @since 1.0 * @version $Revision$ */ class Doctrine_Record_SerializeUnserialize_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { $this->tables[] = 'SerializeTest'; parent::prepareTables(); } public function prepareData() { } public function testSerializeUnserialize() { $object = new SerializeTest(); $object->booltest = true; $object->integertest = 13; $object->floattest = 0.13; $object->stringtest = 'string'; $object->arraytest = array(1, 2, 3); $object->objecttest = new TestObject(13); $object->enumtest = 'java'; $object->blobtest = 'blobtest'; $object->clobtest = 'clobtest'; $object->gziptest = 'gziptest'; $object->timestamptest = '2007-08-07 11:55:00'; $object->timetest = '11:55:00'; $object->datetest = '2007-08-07'; $object->save(); $object_before = clone($object); $serialized = serialize($object); $object_after = unserialize($serialized); $this->assertIdentical($object_before->booltest, $object_after->booltest); $this->assertIdentical($object_before->integertest, $object_after->integertest); $this->assertIdentical($object_before->floattest, $object_after->floattest); $this->assertIdentical($object_before->stringtest, $object_after->stringtest); $this->assertIdentical($object_before->arraytest, $object_after->arraytest); $this->assertIdentical($object_before->enumtest, $object_after->enumtest); $this->assertEqual($object_before->objecttest, $object_after->objecttest); $this->assertIdentical($object_before->blobtest, $object_after->blobtest); $this->assertIdentical($object_before->clobtest, $object_after->clobtest); $this->assertIdentical($object_before->gziptest, $object_after->gziptest); $this->assertIdentical($object_before->timestamptest, $object_after->timestamptest); $this->assertIdentical($object_before->timetest, $object_after->timetest); $this->assertIdentical($object_before->datetest, $object_after->datetest); } public function testSerializeUnserializeRecord() { $test = new TestRecord(); $test->save(); $object = new SerializeTest(); $object->objecttest = $test; $object->save(); $object_before = clone($object); $serialized = serialize($object); $object_after = unserialize($serialized); $this->assertIdentical(get_class($object_after->objecttest), 'TestRecord'); } } class TestObject { private $test_field; public function __construct($value) { $this->test_field = $value; } }