File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / tests / classes / serialize_001.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:48:06 2012 UTC (12 years, 4 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, v5_3_10, HEAD
php

    1: --TEST--
    2: ZE2 Serializable
    3: --FILE--
    4: <?php
    5: 
    6: class Test implements Serializable
    7: {
    8: 	public $data;
    9: 
   10: 	function __construct($data)
   11: 	{
   12: 		echo __METHOD__ . "($data)\n";
   13: 		$this->data = $data;
   14: 	}
   15: 
   16: 	function serialize()
   17: 	{
   18: 		echo __METHOD__ . "({$this->data})\n";
   19: 		return $this->data;
   20: 	}
   21: 
   22: 	function unserialize($serialized)
   23: 	{
   24: 		echo __METHOD__ . "($serialized)\n";
   25: 		$this->data = $serialized;
   26: 		var_dump($this);
   27: 	}
   28: }
   29: 
   30: $tests = array('String', NULL, 42, false);
   31: 
   32: foreach($tests as $data)
   33: {
   34: 	try
   35: 	{
   36: 		echo "==========\n";
   37: 		var_dump($data);
   38: 		$ser = serialize(new Test($data));
   39: 		var_dump(unserialize($ser));
   40: 	}
   41: 	catch(Exception $e)
   42: 	{
   43: 		echo 'Exception: ' . $e->getMessage() . "\n";
   44: 	}
   45: }
   46: 
   47: ?>
   48: ===DONE===
   49: <?php exit(0); ?>
   50: --EXPECTF--
   51: ==========
   52: %unicode|string%(6) "String"
   53: Test::__construct(String)
   54: Test::serialize(String)
   55: Test::unserialize(String)
   56: object(Test)#%d (1) {
   57:   [%u|b%"data"]=>
   58:   %unicode|string%(6) "String"
   59: }
   60: object(Test)#%d (1) {
   61:   [%u|b%"data"]=>
   62:   %unicode|string%(6) "String"
   63: }
   64: ==========
   65: NULL
   66: Test::__construct()
   67: Test::serialize()
   68: NULL
   69: ==========
   70: int(42)
   71: Test::__construct(42)
   72: Test::serialize(42)
   73: Exception: Test::serialize() must return a string or NULL
   74: ==========
   75: bool(false)
   76: Test::__construct()
   77: Test::serialize()
   78: Exception: Test::serialize() must return a string or NULL
   79: ===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>