Skip to content

Commit 9e49400

Browse files
committed
fix tests
1 parent 97d9a35 commit 9e49400

File tree

6 files changed

+14
-38
lines changed

6 files changed

+14
-38
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@
1919
/Dockerfile.bak
2020
/html/*
2121
/.idea
22-
*.pid

examples/remote-object/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
remote-object-server.sock
2+
remote-object-server.log
3+
remote-object-server.pid
4+
remote-object-server.php
5+
remote-object-server.lock
Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,3 @@ public function count(): int
8181
return count($this->list);
8282
}
8383
}
84-
85-
//$server = new Swoole\RemoteObject\Server(options: [
86-
// 'worker_num' => 4,
87-
// 'server_mode' => SWOOLE_BASE,
88-
// 'enable_coroutine' => false,
89-
// 'bootstrap' => __FILE__,
90-
// 'pid_file' => __DIR__ . '/server.pid',
91-
//]);
92-
//$server->start();
93-
94-
require_once dirname(__DIR__, 2) . '/src/ext/standard.php';
95-
96-
(new Swoole\RemoteObject\Server('/home/swoole/.swoole/remote-object-server.sock', 0, [
97-
'worker_num' => 8,
98-
'server_mode' => 3,
99-
'enable_coroutine' => false,
100-
'bootstrap' => __FILE__,
101-
'pid_file' => '/home/swoole/.swoole/remote-object-server.pid',
102-
'log_file' => '/home/swoole/.swoole/remote-object-server.log',
103-
'socket_type' => 5,
104-
]))->start();

src/functions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ function swoole_init_default_remote_object_server(): void
229229

230230
file_put_contents($php_file, '<?php' .
231231
"\nif (is_file(__DIR__ . '/vendor/autoload.php')) { require __DIR__ . '/vendor/autoload.php'; }" .
232+
"\nif (is_file(__DIR__ . '/bootstrap.php')) { require __DIR__ . '/bootstrap.php'; }" .
233+
"\n" .
232234
"\n(new Swoole\\RemoteObject\\Server("
233235
. "'{$socket_file}', 0, "
234236
. var_export($options, true) .

tests/bootstrap.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,5 @@
6868
const DOCUMENT_ROOT = '/var/www/tests/www';
6969

7070
$remote_object_dir = dirname(__DIR__) . '/examples/remote-object';
71-
72-
if (!is_file($remote_object_dir . '/server.pid')
73-
or !posix_kill(intval(file_get_contents($remote_object_dir . '/server.pid')), 0)) {
74-
$process = new Swoole\Process(function (Swoole\Process $process) use ($remote_object_dir) {
75-
include $remote_object_dir . '/server.php';
76-
});
77-
$process->start();
78-
register_shutdown_function(function () use ($process) {
79-
Swoole\Process::kill($process->pid);
80-
});
81-
}
71+
swoole_library_set_option('default_remote_object_server_worker_num', 8);
72+
swoole_library_set_option('default_remote_object_server_dir', $remote_object_dir);

tests/unit/RemoteObjectTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class RemoteObjectTest extends TestCase
2929
public function testCallFunction(): void
3030
{
3131
run(function () {
32-
$client = new RemoteObject\Client('127.0.0.1', RemoteObject\Server::DEFAULT_PORT);
32+
$client = swoole_get_default_remote_object_client();
3333
$this->assertEquals('x86_64', $client->call('php_uname', 'm'));
3434
$gd_info = $client->call('gd_info');
3535
$this->assertIsArray($gd_info);
@@ -40,7 +40,7 @@ public function testCallFunction(): void
4040
public function testInvoke()
4141
{
4242
run(function () {
43-
$client = new RemoteObject\Client('127.0.0.1', RemoteObject\Server::DEFAULT_PORT);
43+
$client = swoole_get_default_remote_object_client();
4444
$o = $client->create(\Greeter::class, 'Hello swoole');
4545
$this->assertEquals('Hello swoole, my name is Tianfeng.Han!', $o('my name is Tianfeng.Han'));
4646
});
@@ -49,7 +49,7 @@ public function testInvoke()
4949
public function testIterator()
5050
{
5151
run(function () {
52-
$client = new RemoteObject\Client('127.0.0.1', RemoteObject\Server::DEFAULT_PORT);
52+
$client = swoole_get_default_remote_object_client();
5353
$o = $client->create(\Greeter::class, 'hello swoole');
5454
$list = iterator_to_array($o);
5555
$this->assertEquals($list, $o->list);
@@ -60,7 +60,7 @@ public function testIterator()
6060
public function testResource()
6161
{
6262
run(function () {
63-
$client = new RemoteObject\Client('127.0.0.1', RemoteObject\Server::DEFAULT_PORT);
63+
$client = swoole_get_default_remote_object_client();
6464
$fp = $client->call('fopen', '/tmp/data.txt', 'w');
6565

6666
$n = random_int(1024, 65536);
@@ -85,7 +85,7 @@ public function testMongoDb(): void
8585

8686
public function __construct()
8787
{
88-
$this->roClient = new RemoteObject\Client();
88+
$this->roClient = swoole_get_default_remote_object_client();
8989
$client = $this->roClient->create(\MongoDB\Client::class, MONGODB_SERVER_URL);
9090
$this->collection = $client->myDatabase->users;
9191
}

0 commit comments

Comments
 (0)