-
Notifications
You must be signed in to change notification settings - Fork 4
/
CtxTest.php
84 lines (69 loc) · 1.9 KB
/
CtxTest.php
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
84
<?php
namespace Tests\Jetea;
use Tests\Jetea\Ctx\Ctx;
/**
* 单元测试
*/
class CtxTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Ctx
*/
protected $ctx;
public function __construct($name = null, $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);
//初始化用于测试的ctx单例对象
$this->ctx = Ctx::getInstance();
}
public function testExampleService()
{
$ret = $this->ctx->Example->setMessage('Ctx.');
$this->assertEquals(true, $ret);
$ret = $this->ctx->Example->getMessage();
$this->assertEquals('hello Ctx.', $ret);
//factory
/** @var Ctx $ctx */
$ctx = Ctx::getInstance();
$ret = $ctx->Example->getMessage();
$this->assertEquals('hello Ctx.', $ret);
}
public function testExampleServiceRpc()
{
$modName = 'Example';
$args = [1, 2, 3];
$method = 'rpc';
$rpcResult = $this->ctx->$modName->$method(...$args);
$this->assertEquals($rpcResult, sprintf(
'rpc host: %s, moduleName: %s, method: %s, args: %s',
\Tests\Jetea\Ctx\Service\Example\Ctx::EXAMPLE_CTX_RPC_HOST,
$modName,
$method,
var_export($args, true)
));
}
public function testCallUndefinedRpcMethod()
{
try {
$this->ctx->Example->rpc1();
$this->assertTrue(false);
} catch (\Exception $e) {
$this->assertTrue(true);
}
}
public function testLoadC1()
{
$this->ctx->Example->loadCTest1();
$this->assertTrue(true);
}
public function testLoadC2()
{
$this->ctx->Example->loadCTest2();
$this->assertTrue(true);
}
public function testLoadC3()
{
$this->expectException(\Error::class);
$this->ctx->Example->loadCTest3();
}
}