xref: /PHP-7.1/ext/session/tests/bug71162.phpt (revision 3d6e9223)
1--TEST--
2updateTimestamp never called when session data is empty
3--INI--
4session.use_strict_mode=0
5session.save_handler=files
6--XFAIL--
7Current session module is designed to write empty session always. In addition, current session module only supports SessionHandlerInterface only from PHP 7.0.
8--FILE--
9<?php
10class MySessionHandler extends SessionHandler implements SessionUpdateTimestampHandlerInterface
11{
12    public function open($path, $sessname) {
13        return TRUE;
14    }
15
16    public function close() {
17        return TRUE;
18    }
19
20    public function read($sessid) {
21        return '';
22    }
23
24    public function write($sessid, $sessdata) {
25        echo __FUNCTION__, PHP_EOL;
26        return TRUE;
27    }
28
29    public function destroy($sessid) {
30        return TRUE;
31    }
32
33    public function gc($maxlifetime) {
34        return TRUE;
35    }
36
37	public function create_sid() {
38		return sha1(random_bytes(32));
39	}
40
41	public function validateId($sid) {
42		return TRUE;
43	}
44
45    public function updateTimestamp($sessid, $sessdata) {
46        echo __FUNCTION__, PHP_EOL;
47        return TRUE;
48    }
49}
50
51ob_start();
52$handler = new MySessionHandler();
53session_set_save_handler($handler);
54
55session_id(sha1(''));
56var_dump(session_id());
57var_dump(session_start(['lazy_write'=>1]));
58session_commit();
59
60session_id(sha1(''));
61var_dump(session_id());
62var_dump(session_start(['lazy_write'=>1]));
63session_commit();
64
65session_id(sha1(''));
66var_dump(session_id());
67var_dump(session_start(['lazy_write'=>0]));
68session_commit();
69?>
70--EXPECT--
71string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709"
72bool(true)
73write
74string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709"
75bool(true)
76updateTimestamp
77string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709"
78bool(true)
79write
80