1 | <?php |
||
2 | namespace Tests\Gateways; |
||
3 | |||
4 | use Tests\TestCase; |
||
5 | use tinymeng\OAuth2\OAuth; |
||
6 | use tinymeng\OAuth2\Helper\ConstCode; |
||
7 | |||
8 | class WechatTest extends TestCase |
||
9 | { |
||
10 | protected $oauth; |
||
11 | |||
12 | protected function setUp(): void |
||
13 | { |
||
14 | parent::setUp(); |
||
15 | $this->oauth = OAuth::wechat($this->getConfig('wechat')); |
||
16 | } |
||
17 | |||
18 | public function testGetRedirectUrl() |
||
19 | { |
||
20 | $url = $this->oauth->getRedirectUrl(); |
||
21 | $this->assertContains('https://open.weixin.qq.com/connect/qrconnect', $url); |
||
22 | $this->assertContains('appid=test_app_id', $url); |
||
23 | } |
||
24 | |||
25 | public function testUserInfo() |
||
26 | { |
||
27 | // 模拟返回数据 |
||
28 | $mockData = [ |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
29 | 'openid' => 'test_openid', |
||
30 | 'nickname' => 'test_name', |
||
31 | 'sex' => 1, |
||
32 | 'headimgurl' => 'http://test.com/avatar.jpg', |
||
33 | ]; |
||
34 | |||
35 | // 验证返回格式 |
||
36 | $userInfo = [ |
||
37 | 'open_id' => 'test_openid', |
||
38 | 'union_id' => '', |
||
39 | 'channel' => ConstCode::TYPE_WECHAT, |
||
40 | 'nickname' => 'test_name', |
||
41 | 'gender' => 1, |
||
42 | 'avatar' => 'http://test.com/avatar.jpg', |
||
43 | 'type' => ConstCode::getTypeConst(ConstCode::TYPE_WECHAT, null), |
||
44 | ]; |
||
45 | |||
46 | $this->assertEquals($userInfo['channel'], ConstCode::TYPE_WECHAT); |
||
47 | } |
||
48 | } |