Repository navigation
Expand file tree
/
Copy pathverify_compat.php
More file actions
70 lines (59 loc) · 2.46 KB
/
Copy pathverify_compat.php
File metadata and controls
70 lines (59 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types=1);
require __DIR__.'/vendor/autoload.php';
use Guanguans\SoarPHP\Soar;
use Guanguans\SoarPHP\Support\OsHelper;
use Wilbur\HyperfSoar\SoarService;
$failures = 0;
function check(string $name, bool $ok): void
{
global $failures;
printf("[%s] %s\n", $ok ? 'PASS' : 'FAIL', $name);
$ok || $failures++;
}
// 1. OsHelper::isWindows 存在(替代旧 OS 类)
check('OsHelper::isWindows() 存在且可调用', is_bool(OsHelper::isWindows()));
// 2. Soar 构造函数签名兼容
$ctor = (new ReflectionClass(Soar::class))->getConstructor();
check('Soar 构造函数存在', $ctor !== null);
check(
'Soar 构造函数签名 (array $options = [], ?string $binary = null)',
$ctor !== null && $ctor->getNumberOfParameters() === 2
);
// 3. score() 单数方法不存在(已移除),jsonScores 存在
check('score() 已移除(返回 false)', !method_exists(Soar::class, 'score'));
check('jsonScores() 存在', method_exists(Soar::class, 'jsonScores'));
check('scores() 存在', method_exists(Soar::class, 'scores'));
check('htmlScores() 存在(新功能)', method_exists(Soar::class, 'htmlScores'));
check('markdownScores() 存在(新功能)', method_exists(Soar::class, 'markdownScores'));
check('arrayScores() 存在(新功能)', method_exists(Soar::class, 'arrayScores'));
check('make() 静态工厂存在(新功能)', method_exists(Soar::class, 'make'));
// 4. SoarService 可实例化,jsonScores 方法签名与调用兼容
$service = new SoarService([
'enabled' => true,
'cut_classes' => [],
'-soar-path' => PHP_BINARY,
'-test-dsn' => [
'host' => '127.0.0.1',
'port' => '3306',
'user' => 'root',
'password' => '',
'schema' => 'test',
'disable' => true,
],
]);
check('SoarService 实例化成功', $service instanceof Soar);
// 5. jsonScores 可调用(二进制不存在会抛进程异常,属预期;验证无 undefined method / TypeError)
try {
$result = $service->jsonScores('SELECT 1');
check('jsonScores() 返回 string', is_string($result));
} catch (\Throwable $e) {
$class = get_class($e);
check(
'jsonScores() 调用链正常(仅因二进制缺失抛 '.$class.',非 API 不兼容)',
!in_array($class, ['Error', 'TypeError'], true) && !str_contains($e->getMessage(), 'Undefined method')
);
echo ' -> '.$e->getMessage()."\n";
}
echo $failures ? "\n{$failures} FAILED\n" : "\nALL PASSED\n";
exit($failures ? 1 : 0);