Annotation of embedaddon/php/ext/session/tests/session_set_save_handler_iface_002.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test session_set_save_handler() function: interface wrong
! 3: --INI--
! 4: session.save_handler=files
! 5: session.name=PHPSESSID
! 6: --SKIPIF--
! 7: <?php include('skipif.inc'); ?>
! 8: --FILE--
! 9: <?php
! 10:
! 11: ob_start();
! 12:
! 13: /*
! 14: * Prototype : bool session_set_save_handler(SessionHandlerInterface $handler [, bool $register_shutdown_function = true])
! 15: * Description : Sets user-level session storage functions
! 16: * Source code : ext/session/session.c
! 17: */
! 18:
! 19: echo "*** Testing session_set_save_handler() function: interface wrong ***\n";
! 20:
! 21: interface MySessionHandlerInterface {
! 22: public function open($path, $name);
! 23: public function close();
! 24: public function read($id);
! 25: public function write($id, $data);
! 26: public function destroy($id);
! 27: public function gc($maxlifetime);
! 28: }
! 29:
! 30: class MySession2 implements MySessionHandlerInterface {
! 31: public $path;
! 32:
! 33: public function open($path, $name) {
! 34: if (!$path) {
! 35: $path = '/tmp';
! 36: }
! 37: $this->path = $path . '/u_sess_' . $name;
! 38: return true;
! 39: }
! 40:
! 41: public function close() {
! 42: return true;
! 43: }
! 44:
! 45: public function read($id) {
! 46: return @file_get_contents($this->path . $id);
! 47: }
! 48:
! 49: public function write($id, $data) {
! 50: echo "Unsupported session handler in use\n";
! 51: }
! 52:
! 53: public function destroy($id) {
! 54: @unlink($this->path . $id);
! 55: }
! 56:
! 57: public function gc($maxlifetime) {
! 58: foreach (glob($this->path . '*') as $filename) {
! 59: if (filemtime($filename) + $maxlifetime < time()) {
! 60: @unlink($filename);
! 61: }
! 62: }
! 63: return true;
! 64: }
! 65: }
! 66:
! 67: function good_write($id, $data) {
! 68: global $handler;
! 69: echo "good handler writing\n";
! 70: return file_put_contents($handler->path . $id, $data);
! 71: }
! 72:
! 73: $handler = new MySession2;
! 74:
! 75: $ret = session_set_save_handler(array($handler, 'open'), array($handler, 'close'),
! 76: array($handler, 'read'), 'good_write', array($handler, 'destroy'), array($handler, 'gc'));
! 77:
! 78: var_dump($ret);
! 79: $ret = session_set_save_handler($handler);
! 80: var_dump($ret);
! 81:
! 82: session_start();
! 83:
! 84: --EXPECTF--
! 85: *** Testing session_set_save_handler() function: interface wrong ***
! 86: bool(true)
! 87:
! 88: Warning: session_set_save_handler() expects parameter 1 to be SessionHandlerInterface, object given in %s
! 89: bool(false)
! 90: good handler writing
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>