Skip to content

Commit b1643e1

Browse files
committed
Fix failed tests for phar
- when $status is boolean, E_NOTICE appears and tests fail - opcache is never enabled on these tests anyway. - Add opcache.revalidate_freq=0 to testing script Instead of checking this in the tests files it can be used directly in the main testing script. Also this fixes failed tests. - Use opcache_invalidate() instead of sleep() delay in some tests. Some delays are still used since the opcache_invalidate seems to be buggy and not working as expected. Closes GH-4392
1 parent f5227c5 commit b1643e1

10 files changed

+22
-65
lines changed

ext/phar/tests/create_new_and_modify.phpt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ $sig1 = $phar->getSignature();
2121
include $pname . '/a.php';
2222

2323
if (function_exists("opcache_get_status")) {
24-
$status = opcache_get_status();
25-
if ($status["opcache_enabled"] || (isset($status["file_cache_only"]) && $status["file_cache_only"])) {
26-
ini_set("opcache.revalidate_freq", "0");
27-
sleep(2);
28-
}
24+
$status = opcache_get_status();
25+
if (is_array($status) && ($status["opcache_enabled"] || (isset($status["file_cache_only"]) && $status["file_cache_only"]))) {
26+
opcache_invalidate($pname . '/a.php', true);
27+
// opcache_invalidate is buggy and doesn't work as expected so we add a
28+
// minor delay here.
29+
sleep(2);
30+
}
2931
}
3032

3133
file_put_contents($pname .'/a.php', "modified!\n");

ext/phar/tests/delete_in_phar.phpt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ $files['a.php'] = '<?php echo "This is a\n"; ?>';
1616
$files['b.php'] = '<?php echo "This is b\n"; ?>';
1717
$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
1818

19-
if (function_exists("opcache_get_status")) {
20-
$status = opcache_get_status();
21-
if ($status["opcache_enabled"]) {
22-
ini_set("opcache.revalidate_freq", "0");
23-
sleep(2);
24-
}
25-
}
26-
2719
include 'files/phar_test.inc';
2820

2921
include $pname . '/a.php';
@@ -54,4 +46,3 @@ Warning: include(%sdelete_in_phar.phar.php/b/c.php): failed to open stream: phar
5446
Warning: include(): Failed opening 'phar://%sdelete_in_phar.phar.php/b/c.php' for inclusion (include_path='%s') in %sdelete_in_phar.php on line %d
5547

5648
===DONE===
57-

ext/phar/tests/delete_in_phar_confirm.phpt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ $files['a.php'] = '<?php echo "This is a\n"; ?>';
1616
$files['b.php'] = '<?php echo "This is b\n"; ?>';
1717
$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
1818

19-
if (function_exists("opcache_get_status")) {
20-
$status = opcache_get_status();
21-
if ($status["opcache_enabled"]) {
22-
ini_set("opcache.revalidate_freq", "0");
23-
sleep(2);
24-
}
25-
}
26-
2719
include 'files/phar_test.inc';
2820

2921
include $pname . '/a.php';

ext/phar/tests/tar/create_new_and_modify.phpt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ $pname = 'phar://' . $fname;
1515
file_put_contents($pname . '/a.php', "brand new!\n");
1616

1717
if (function_exists("opcache_get_status")) {
18-
$status = opcache_get_status();
19-
if ($status["opcache_enabled"] || (isset($status["file_cache_only"]) && $status["file_cache_only"])) {
20-
ini_set("opcache.revalidate_freq", "0");
21-
sleep(2);
22-
}
18+
$status = opcache_get_status();
19+
if (is_array($status) && ($status["opcache_enabled"] || (isset($status["file_cache_only"]) && $status["file_cache_only"]))) {
20+
opcache_invalidate($pname . '/a.php', true);
21+
// opcache_invalidate is buggy and doesn't work as expected so we add a
22+
// minor delay here.
23+
sleep(2);
24+
}
2325
}
2426

2527
$phar = new Phar($fname);

ext/phar/tests/tar/delete_in_phar.phpt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ $phar['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
1818
$phar->setStub('<?php __HALT_COMPILER(); ?>');
1919
$phar->stopBuffering();
2020

21-
if (function_exists("opcache_get_status")) {
22-
$status = opcache_get_status();
23-
if ($status["opcache_enabled"]) {
24-
ini_set("opcache.revalidate_freq", "0");
25-
sleep(2);
26-
}
27-
}
28-
2921
include $alias . '/a.php';
3022
include $alias . '/b.php';
3123
include $alias . '/b/c.php';

ext/phar/tests/tar/delete_in_phar_confirm.phpt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ $phar['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
1818
$phar->setStub('<?php __HALT_COMPILER(); ?>');
1919
$phar->stopBuffering();
2020

21-
if (function_exists("opcache_get_status")) {
22-
$status = opcache_get_status();
23-
if ($status["opcache_enabled"]) {
24-
ini_set("opcache.revalidate_freq", "0");
25-
sleep(2);
26-
}
27-
}
28-
2921
include $alias . '/a.php';
3022
include $alias . '/b.php';
3123
include $alias . '/b/c.php';

ext/phar/tests/zip/create_new_and_modify.phpt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ $pname = 'phar://' . $fname;
1515
file_put_contents($pname . '/a.php', "brand new!\n");
1616

1717
if (function_exists("opcache_get_status")) {
18-
$status = opcache_get_status();
19-
if ($status["opcache_enabled"] || (isset($status["file_cache_only"]) && $status["file_cache_only"])) {
20-
ini_set("opcache.revalidate_freq", "0");
21-
sleep(2);
22-
}
18+
$status = opcache_get_status();
19+
if (is_array($status) && ($status["opcache_enabled"] || (isset($status["file_cache_only"]) && $status["file_cache_only"]))) {
20+
opcache_invalidate($pname . '/a.php', true);
21+
// opcache_invalidate is buggy and doesn't work as expected so we add a
22+
// minor delay here.
23+
sleep(2);
24+
}
2325
}
2426

2527
$phar = new Phar($fname);

ext/phar/tests/zip/delete_in_phar.phpt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ $phar['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
1818
$phar->setStub('<?php __HALT_COMPILER(); ?>');
1919
$phar->stopBuffering();
2020

21-
if (function_exists("opcache_get_status")) {
22-
$status = opcache_get_status();
23-
if ($status["opcache_enabled"]) {
24-
ini_set("opcache.revalidate_freq", "0");
25-
sleep(2);
26-
}
27-
}
28-
2921
include $alias . '/a.php';
3022
include $alias . '/b.php';
3123
include $alias . '/b/c.php';
@@ -54,4 +46,3 @@ Warning: include(%sdelete_in_phar.phar.zip/b/c.php): failed to open stream: phar
5446
Warning: include(): Failed opening 'phar://%sdelete_in_phar.phar.zip/b/c.php' for inclusion (include_path='%s') in %sdelete_in_phar.php on line %d
5547

5648
===DONE===
57-

ext/phar/tests/zip/delete_in_phar_confirm.phpt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ $phar['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
1818
$phar->setStub('<?php __HALT_COMPILER(); ?>');
1919
$phar->stopBuffering();
2020

21-
if (function_exists("opcache_get_status")) {
22-
$status = opcache_get_status();
23-
if ($status["opcache_enabled"]) {
24-
ini_set("opcache.revalidate_freq", "0");
25-
sleep(2);
26-
}
27-
}
28-
2921
include $alias . '/a.php';
3022
include $alias . '/b.php';
3123
include $alias . '/b/c.php';

run-tests.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ function main()
258258
'log_errors_max_len=0',
259259
'opcache.fast_shutdown=0',
260260
'opcache.file_update_protection=0',
261+
'opcache.revalidate_freq=0',
261262
'zend.assertions=1',
262263
);
263264

0 commit comments

Comments
 (0)