-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathcheck_callback.phpt
83 lines (74 loc) · 2.81 KB
/
check_callback.phpt
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
71
72
73
74
75
76
77
78
79
80
81
82
83
--TEST--
swoole_server: check callback
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
use Swoole\Constant;
use Swoole\Process;
function test_create_server($class, $callback)
{
$proc = new Process(function () use ($class) {
$server = new $class('127.0.0.1');
$server->start();
}, true, SOCK_STREAM, false);
$proc->start();
$result = Process::wait();
Assert::contains($proc->read(), 'require on'.ucfirst($callback).' callback');
Assert::eq($result['code'], 255);
}
test_create_server(Swoole\Server::class, Constant::EVENT_RECEIVE);
test_create_server(Swoole\Http\Server::class, Constant::EVENT_REQUEST);
test_create_server(Swoole\WebSocket\Server::class, Constant::EVENT_MESSAGE);
$proc = new Process(function () {
$server = new Swoole\Server('127.0.0.1', 0, SWOOLE_BASE, SWOOLE_SOCK_UDP);
$server->start();
}, true, SOCK_STREAM, false);
$proc->start();
$result = Process::wait();
Assert::contains($proc->read(), 'require onPacket callback');
Assert::eq($result['code'], 255);
$proc = new Process(function () {
$server = new Swoole\Server('127.0.0.1', 0, SWOOLE_BASE, SWOOLE_SOCK_UDP);
$server->on(Constant::EVENT_PACKET, function () {});
$server->addlistener('127.0.0.1', 0, SWOOLE_SOCK_TCP);
$server->start();
}, true, SOCK_STREAM, false);
$proc->start();
$result = Process::wait();
Assert::contains($proc->read(), 'require onReceive callback');
Assert::eq($result['code'], 255);
$proc = new Process(function () {
$server = new Swoole\Server('127.0.0.1', 0, SWOOLE_BASE, SWOOLE_SOCK_TCP);
$server->on(Constant::EVENT_RECEIVE, function () {});
$server->addlistener('127.0.0.1', 0, SWOOLE_SOCK_UDP);
$server->start();
}, true, SOCK_STREAM, false);
$proc->start();
$result = Process::wait();
Assert::contains($proc->read(), 'require onPacket callback');
Assert::eq($result['code'], 255);
$proc = new Process(function () {
$server = new Swoole\Http\Server('127.0.0.1', 0, SWOOLE_BASE, SWOOLE_SOCK_TCP);
$server->on(Constant::EVENT_REQUEST, function () {});
$server->addlistener('127.0.0.1', 0, SWOOLE_SOCK_UDP);
$server->start();
}, true, SOCK_STREAM, false);
$proc->start();
$result = Process::wait();
Assert::contains($proc->read(), 'require onPacket callback');
Assert::eq($result['code'], 255);
$proc = new Process(function () {
$server = new Swoole\Http\Server('127.0.0.1', 0, SWOOLE_BASE, SWOOLE_SOCK_TCP);
$server->on(Constant::EVENT_REQUEST, function () {});
$port = $server->addlistener('127.0.0.1', 0, SWOOLE_SOCK_TCP);
$port->set(['open_http_protocol' => false]);
$server->start();
}, true, SOCK_STREAM, false);
$proc->start();
$result = Process::wait();
Assert::contains($proc->read(), 'require onReceive callback');
Assert::eq($result['code'], 255);
?>
--EXPECT--