ClientTest.php
1.7 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
<?php
namespace AukeySwrpcTests;
use AukeySwrpc\Register\Consul;
use AukeySwrpc\Register\Service;
use AukeySwrpc\Request;
use AukeySwrpc\Client;
/**
* 客户端单元测试
* php74 ../phpunit.phar tests/ClientTest.php --debug
* Class ClientTest
*
* @link http://www.phpunit.cn/manual/7.0/zh_cn/index.html
* @author pengjch 2024312 9:39:22
*/
class ClientTest extends BootTest
{
/**
* @return Client Client
* @author pengjch 2024312 14:29:28
*/
public function testClientConnect(): Client
{
$client = Client::create('School_Module', getenv('RPC_SERVER_HOST'), getenv('RPC_SERVER_PORT'));
$conn = $client->connect();
$this->assertIsBool($conn->isConnected(), 'Client connect failure.');
return $client;
}
/**
* @depends testClientConnect
* @param Client $client
* @author pengjch 2024312 14:29:20
*/
public function testClientSyncRequest($client)
{
$request = Request\SyncRequest::create('AukeySwrpcTests\services\SchoolService_getUserSchool', [1, 1]);
$res = $client->send($request);
$this->assertEquals('未来学校1', $res);
}
/**
* @depends testClientConnect
* @param $client
* @author pengjch 2024313 10:3:43
*/
public function testClientAsyncRequest($client)
{
$request = Request\AsyncRequest::create('AukeySwrpcTests\services\SchoolService_saveUserName', ['tony']);
$res = $client->send($request);
$this->assertEquals('success', $res);
sleep(3);
$this->assertFileExists('xxx.log', 'Async request failure.');
$value = file_get_contents('xxx.log');
$this->assertEquals('tony', $value);
@unlink('xxx.log');
}
}