Skip to content

Commit c5734c0

Browse files
committed
improve unit tests
1 parent d1b74e9 commit c5734c0

15 files changed

+950
-285
lines changed

ext/opcache/tests/gh16551_001.phpt

Lines changed: 0 additions & 42 deletions
This file was deleted.

ext/opcache/tests/gh16551_002.phpt

Lines changed: 0 additions & 37 deletions
This file was deleted.

ext/opcache/tests/gh16551_003.phpt

Lines changed: 0 additions & 41 deletions
This file was deleted.

ext/opcache/tests/gh16551_004.phpt

Lines changed: 0 additions & 36 deletions
This file was deleted.

ext/opcache/tests/gh16551_005.phpt

Lines changed: 0 additions & 32 deletions
This file was deleted.

ext/opcache/tests/gh16551_099.phpt

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
--TEST--
2+
GH-16551: Behavior with opcache.file_cache_only=1
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('Zend OPcache')) die('skip Zend OPcache extension not available');
6+
7+
// Ensure the cache directory exists BEFORE OPcache needs it
8+
$cacheDir = __DIR__ . '/gh16551_fileonly_cache';
9+
if (!is_dir($cacheDir)) {
10+
@mkdir($cacheDir, 0777, true);
11+
}
12+
// Check if mkdir failed potentially due to permissions
13+
if (!is_dir($cacheDir) || !is_writable($cacheDir)) {
14+
die('skip Could not create or write to cache directory: ' . $cacheDir);
15+
}
16+
?>
17+
--INI--
18+
opcache.enable=1
19+
opcache.enable_cli=1
20+
opcache.jit=disable
21+
opcache.jit_buffer_size=0
22+
opcache.file_cache="{PWD}/gh16551_fileonly_cache"
23+
opcache.file_cache_only=1
24+
opcache.validate_timestamps=1
25+
--EXTENSIONS--
26+
opcache
27+
--FILE--
28+
<?php
29+
$file = __DIR__ . '/gh16551_998.inc';
30+
$uncached_file = __DIR__ . '/gh16551_999.inc';
31+
$cacheDir = __DIR__ . '/gh16551_fileonly_cache';
32+
33+
echo "Initial state (file_cache_only mode):\n";
34+
// SHM is always false, File Cache might be true in Pass 2
35+
var_dump(opcache_is_script_cached($file));
36+
var_dump(opcache_is_script_cached_in_file_cache($file));
37+
38+
echo "\nAttempting opcache_compile_file():\n";
39+
opcache_compile_file($file);
40+
41+
echo "\nState after compile attempt:\n";
42+
// SHM remains false, File Cache becomes true
43+
var_dump(opcache_is_script_cached($file));
44+
var_dump(opcache_is_script_cached_in_file_cache($file));
45+
46+
// Check file existence via glob
47+
echo "\nChecking file system for compiled file:\n";
48+
if (substr(PHP_OS, 0, 3) === 'WIN') {
49+
$sanitizedDir = str_replace(':', '', __DIR__);
50+
$pattern = $cacheDir . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $sanitizedDir . DIRECTORY_SEPARATOR . 'gh16551_998.inc.bin';
51+
} else {
52+
$pattern = $cacheDir . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . __DIR__ . DIRECTORY_SEPARATOR . 'gh16551_998.inc.bin';
53+
}
54+
$found = glob($pattern);
55+
var_dump(count($found) > 0); // Expect true after compile
56+
57+
echo "\nAttempting require:\n";
58+
require $file; // Outputs 9, should execute from file cache
59+
60+
echo "\nState after require:\n";
61+
// State remains unchanged
62+
var_dump(opcache_is_script_cached($file));
63+
var_dump(opcache_is_script_cached_in_file_cache($file));
64+
65+
echo "\nChecking uncached file initial state:\n";
66+
// SHM false, File Cache might be true in Pass 2 for this file too
67+
var_dump(opcache_is_script_cached($uncached_file));
68+
var_dump(opcache_is_script_cached_in_file_cache($uncached_file));
69+
70+
echo "\nRequiring uncached file:\n";
71+
require $uncached_file; // Outputs 8, should compile to file cache now
72+
73+
echo "\nState after requiring uncached file:\n";
74+
// SHM remains false, File cache becomes true for this file
75+
var_dump(opcache_is_script_cached($uncached_file));
76+
var_dump(opcache_is_script_cached_in_file_cache($uncached_file));
77+
78+
?>
79+
--CLEAN--
80+
<?php
81+
$baseCacheDir = __DIR__ . '/gh16551_fileonly_cache';
82+
83+
function removeDirRecursive($dir) {
84+
if (!is_dir($dir)) return;
85+
try {
86+
$iterator = new RecursiveIteratorIterator(
87+
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
88+
RecursiveIteratorIterator::CHILD_FIRST
89+
);
90+
foreach ($iterator as $fileinfo) {
91+
if ($fileinfo->isDir()) {
92+
@rmdir($fileinfo->getRealPath());
93+
} else {
94+
@unlink($fileinfo->getRealPath());
95+
}
96+
}
97+
@rmdir($dir);
98+
} catch (UnexpectedValueException $e) { @rmdir($dir); } catch (Exception $e) { @rmdir($dir); }
99+
}
100+
101+
removeDirRecursive($baseCacheDir);
102+
?>
103+
--EXPECTF--
104+
Initial state (file_cache_only mode):
105+
bool(false)
106+
bool(%s)
107+
108+
Attempting opcache_compile_file():
109+
110+
State after compile attempt:
111+
bool(false)
112+
bool(true)
113+
114+
Checking file system for compiled file:
115+
bool(true)
116+
117+
Attempting require:
118+
9
119+
120+
State after require:
121+
bool(false)
122+
bool(true)
123+
124+
Checking uncached file initial state:
125+
bool(false)
126+
bool(%s)
127+
128+
Requiring uncached file:
129+
8
130+
131+
State after requiring uncached file:
132+
bool(false)
133+
bool(true)

0 commit comments

Comments
 (0)