Skip to content

Commit 172d1ff

Browse files
arjenscholsodabrew
authored andcommitted
Fix tests for PHP 7.1 (#297)
invoke_callback_2 fails because of ArgumentCountException (init_cb_arg gets only 2 args) Check number of passed arguments with func_num_args() insteadof checking $args is null session_lock fails because of second warning in 7.1 Skip session_lock.phpt for php < 7.1 and create new testcase for >= 7.1 which tests both warnings. Update .travis.yml, don't allow failures for 7.1 anymore!
1 parent d9dea45 commit 172d1ff

File tree

5 files changed

+74
-14
lines changed

5 files changed

+74
-14
lines changed

.travis.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ php:
88

99
matrix:
1010
fast_finish: true
11-
allow_failures:
12-
- php: 7.1
1311

1412
env:
1513
- LIBMEMCACHED_VERSION=1.0.18 # Debian Jessie / Ubuntu Xenial
@@ -31,6 +29,4 @@ script:
3129

3230
cache:
3331
directories:
34-
- $HOME/cache
35-
36-
32+
- $HOME/cache

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ Tests
165165
<file role='test' name='stats.phpt'/>
166166
<file role='test' name='default_behavior.phpt'/>
167167
<file role='test' name='reset_keyprefix.phpt'/>
168+
<file role='test' name='session_lock-php71.phpt'/>
168169
</dir>
169170
</dir>
170171
</contents>

tests/invoke_callback_2.phpt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ function init_cb_fail($m, $id) {
1818
echo "configured, should not be called.\n";
1919
}
2020

21-
function init_cb_arg($m, $id, $arg) {
21+
function init_cb_arg($m, $id) {
22+
var_dump(func_num_args());
2223
var_dump($id);
23-
var_dump($arg);
2424
}
2525

2626
function init_nopersist_cb($m, $id) {
@@ -33,15 +33,14 @@ class Foo extends Memcached {
3333
parent::__construct($id, array($this, 'init'));
3434
}
3535

36-
function init($obj, $id, $options) {
36+
function init($obj, $id) {
37+
var_dump(func_num_args());
3738
var_dump($this->isPristine());
3839
var_dump($this->isPersistent());
3940
var_dump($id);
4041
}
4142
}
4243

43-
error_reporting(0);
44-
4544
echo "cb call\n";
4645
$m1 = new Memcached('foo1', 'init_cb');
4746

@@ -50,7 +49,6 @@ $m1 = new Memcached('foo1', 'init_cb_fail');
5049

5150
echo "cb arg without arg\n";
5251
$m1 = new Memcached('foo3', 'init_cb_arg');
53-
echo $php_errormsg, "\n";
5452

5553
echo "cb arg not persistent\n";
5654
$m1 = new Memcached(null, 'init_nopersist_cb');
@@ -63,25 +61,26 @@ $m1 = new Foo('baz');
6361

6462
echo "cb second persistent in object\n";
6563
$m1 = new Foo('baz');
66-
64+
?>
6765
--EXPECT--
6866
cb call
6967
string(9) "Memcached"
7068
bool(true)
7169
string(4) "foo1"
7270
cb not run
7371
cb arg without arg
72+
int(2)
7473
string(4) "foo3"
75-
NULL
76-
7774
cb arg not persistent
7875
bool(false)
7976
NULL
8077
cb in object
78+
int(2)
8179
bool(true)
8280
bool(false)
8381
NULL
8482
cb persistent in object
83+
int(2)
8584
bool(true)
8685
bool(true)
8786
string(3) "baz"

tests/session_lock-php71.phpt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
Session lock
3+
--SKIPIF--
4+
<?php
5+
include dirname(__FILE__) . "/skipif.inc";
6+
if (!Memcached::HAVE_SESSION) print "skip";
7+
8+
if (PHP_VERSION_ID < 70100) print "skip";
9+
?>
10+
--INI--
11+
memcached.sess_locking = true
12+
memcached.sess_lock_wait_min = 500
13+
memcached.sess_lock_wait_max = 1000
14+
memcached.sess_lock_retries = 3
15+
memcached.sess_prefix = "memc.test."
16+
17+
session.save_handler = memcached
18+
19+
--FILE--
20+
<?php
21+
22+
include dirname (__FILE__) . '/config.inc';
23+
24+
$m = new Memcached();
25+
$m->addServer(MEMC_SERVER_HOST, MEMC_SERVER_PORT);
26+
27+
ob_start();
28+
ini_set ('session.save_path', MEMC_SERVER_HOST . ':' . MEMC_SERVER_PORT);
29+
30+
session_start();
31+
$session_id = session_id();
32+
33+
$_SESSION["test"] = "hello";
34+
session_write_close();
35+
36+
session_start();
37+
var_dump ($m->get ('memc.test.' . session_id()));
38+
var_dump ($m->get ('memc.test.lock.' . session_id()));
39+
session_write_close();
40+
var_dump ($m->get ('memc.test.lock.' . session_id()));
41+
42+
// Test lock min / max
43+
$m->set ('memc.test.lock.' . $session_id, '1');
44+
45+
$time_start = microtime(true);
46+
session_start();
47+
$time = microtime(true) - $time_start;
48+
49+
if (round ($time, 1) != 2.5) {
50+
echo "Waited longer than expected: $time" . PHP_EOL;
51+
}
52+
echo "OK";
53+
54+
--EXPECTF--
55+
string(17) "test|s:5:"hello";"
56+
string(1) "1"
57+
bool(false)
58+
59+
Warning: session_start(): Unable to clear session lock record in %s on line %d
60+
61+
Warning: session_start(): Failed to read session data: memcached (path: 127.0.0.1:11211) in %s on line %d
62+
OK

tests/session_lock.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Session lock
44
<?php
55
include dirname(__FILE__) . "/skipif.inc";
66
if (!Memcached::HAVE_SESSION) print "skip";
7+
8+
if (PHP_VERSION_ID >= 70100) print "skip";
79
?>
810
--INI--
911
memcached.sess_locking = true

0 commit comments

Comments
 (0)