WechatTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testUserInfo() 0 22 1
A testGetRedirectUrl() 0 5 1
A setUp() 0 4 1
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
The assignment to $mockData is dead and can be removed.
Loading history...
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
}