diff options
author | Arpad Ray <arraypad@gmail.com> | 2013-06-27 12:33:56 +0100 |
---|---|---|
committer | Arpad Ray <arraypad@gmail.com> | 2013-06-27 13:06:22 +0100 |
commit | ada46c75f42cda5a790a921413b6f9f69e2495b4 (patch) | |
tree | def7d2c25142894cdc0e68e7b95e5a17a43d0cb6 /ext/session/tests/session_set_save_handler_sid_002.phpt | |
parent | b794cce4fd4a6158002f3e8a814a30891cefbcde (diff) | |
download | php-git-ada46c75f42cda5a790a921413b6f9f69e2495b4.tar.gz |
BC fix for PR 109 merge - create_sid() method in SessionHandler
Creates a new SessionIdInterface and moves create_sid() into it, so existing
handlers implementing SessionHandlerInterface don't require create_sid().
SessionHandler still includes the method so the default mod can be called, but
now implements both interfaces.
Also added several more tests for this feature.
Diffstat (limited to 'ext/session/tests/session_set_save_handler_sid_002.phpt')
-rw-r--r-- | ext/session/tests/session_set_save_handler_sid_002.phpt | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/ext/session/tests/session_set_save_handler_sid_002.phpt b/ext/session/tests/session_set_save_handler_sid_002.phpt new file mode 100644 index 0000000000..f9a72aebca --- /dev/null +++ b/ext/session/tests/session_set_save_handler_sid_002.phpt @@ -0,0 +1,77 @@ +--TEST-- +Test session_set_save_handler() function: create_sid +--INI-- +session.save_handler=files +session.name=PHPSESSID +--SKIPIF-- +<?php include('skipif.inc'); ?> +--FILE-- +<?php + +ob_start(); + +echo "*** Testing session_set_save_handler() function: create_sid ***\n"; + +class MySession2 { + public $path; + + public function open($path, $name) { + if (!$path) { + $path = sys_get_temp_dir(); + } + $this->path = $path . '/u_sess_' . $name; + return true; + } + + public function close() { + return true; + } + + public function read($id) { + return @file_get_contents($this->path . $id); + } + + public function write($id, $data) { + return file_put_contents($this->path . $id, $data); + } + + public function destroy($id) { + @unlink($this->path . $id); + } + + public function gc($maxlifetime) { + foreach (glob($this->path . '*') as $filename) { + if (filemtime($filename) + $maxlifetime < time()) { + @unlink($filename); + } + } + return true; + } + + public function create_sid() { + return null; + } +} + +$handler = new MySession2; +session_set_save_handler(array($handler, 'open'), array($handler, 'close'), + array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc'), array($handler, 'create_sid')); +session_start(); + +$_SESSION['foo'] = "hello"; + +var_dump(session_id(), ini_get('session.save_handler'), $_SESSION); + +session_write_close(); +session_unset(); + +session_start(); +var_dump($_SESSION); + +session_write_close(); +session_unset(); + +--EXPECTF-- +*** Testing session_set_save_handler() function: create_sid *** + +Fatal error: session_start(): Session id must be a string in %s on line %d |