forked from w7corp/easywechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserUserTest.php
executable file
·108 lines (87 loc) · 2.63 KB
/
UserUserTest.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
use EasyWeChat\User\User;
class UserUserTest extends TestCase
{
public function getUser()
{
$user = Mockery::mock('EasyWeChat\User\User[parseJSON]', [Mockery::mock('EasyWeChat\Core\AccessToken')]);
$user->shouldReceive('parseJSON')->andReturnUsing(function ($method, $params) {
return [
'api' => $params[0],
'params' => empty($params[1]) ? null : $params[1],
];
});
return $user;
}
/**
* Test get().
*/
public function testGet()
{
$user = $this->getUser();
$result = $user->get('openid_fo_overtrue');
$this->assertStringStartsWith(User::API_GET, $result['api']);
$this->assertEquals('openid_fo_overtrue', $result['params']['openid']);
$this->assertEquals('zh_CN', $result['params']['lang']);
}
/**
* Test batchGet().
*/
public function testBatchGet()
{
$user = $this->getUser();
$result = $user->batchGet(['openid1', 'openid2']);
$expected = [
[
'openid' => 'openid1',
'lang' => 'zh_CN',
],
[
'openid' => 'openid2',
'lang' => 'zh_CN',
],
];
$this->assertStringStartsWith(User::API_BATCH_GET, $result['api']);
$this->assertEquals($expected, $result['params']['user_list']);
}
/**
* Test lists().
*/
public function testLists()
{
$user = $this->getUser();
$result = $user->lists('openid1');
$this->assertStringStartsWith(User::API_LIST, $result['api']);
$this->assertEquals('openid1', $result['params']['next_openid']);
}
/**
* Test remark().
*/
public function testRemark()
{
$user = $this->getUser();
$result = $user->remark('openid1', 'easywechat');
$this->assertStringStartsWith(User::API_REMARK, $result['api']);
$this->assertEquals('openid1', $result['params']['openid']);
$this->assertEquals('easywechat', $result['params']['remark']);
}
/**
* Test group().
*/
public function testGroup()
{
$user = $this->getUser();
$result = $user->group('openid1');
$this->assertEquals('openid1', $result['params']['openid']);
$result = $user->getGroup('openid2');
$this->assertEquals('openid2', $result['params']['openid']);
}
}