Passed
Push — master ( 86cde0...e6ca11 )
by Jim
02:02
created

TimCloudTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: lenovo
5
 * Date: 6/15/2018
6
 * Time: 3:28 PM
7
 */
8
9
namespace TimSDK\Tests;
10
11
use Mockery;
12
use TimSDK\Core\API;
13
use TimSDK\Foundation\ResponseBag;
14
use TimSDK\TimCloud;
15
16
class TimCloudTest extends TestCase
17
{
18
    public function testEnv()
19
    {
20
        $this->assertTrue(phpunit_env('phpunit_running'));
21
    }
22
23
    public function testCertPemExist()
24
    {
25
        $t = $this->timCloud();
26
27
        $this->assertTrue(file_exists($t['path.cert'] . '/cacert.pem'));
28
    }
29
30
    public function testRefreshConfiguration()
31
    {
32
        $timCloud = $this->timCloud();
33
34
        $this->assertFalse($timCloud->im->isNeedRefresh());
35
36
        $timCloud->setIdentifier('admin');
37
38
        $this->assertTrue($timCloud->im->isNeedRefresh());
39
40
        $query = $timCloud->im->getRefreshedQueryStringArray();
41
42
        $this->assertSame('admin', $query['identifier']);
43
    }
44
45
    public function testFormatKey()
46
    {
47
        $timCloud = $this->timCloud();
48
49
        $priKeyContent = 'MIGqAgEAAiEAsHYdyE9VvL9gwVBXVQrUFSWiWRTD+A+bgyMizSN8uqcCAwEAAQIg
50
B1LfqZChXlQTD/LlrQHmC2j+E5Fm1+55V/AcT39xGgECEQDauiGoffbvSGVcMPej
51
Qy+5AhEAzogp60smRdoK0RYDE76tXwIRAMl/xbgqa02fHTmkJs6x+4kCEEouJ/hG
52
FqoSJb5xjItj+jsCEBxm38VmLmQgIHwKP3ids9U=';
53
        $pubKeyContent = 'MDwwDQYJKoZIhvcNAQEBBQADKwAwKAIhALB2HchPVby/YMFQV1UK1BUlolkUw/gP
54
m4MjIs0jfLqnAgMBAAE=';
55
56
        $openSSLPrivateKey = "-----BEGIN PRIVATE KEY-----
57
$priKeyContent
58
-----END PRIVATE KEY-----";
59
        $openSSLPublicKey = "-----BEGIN PUBLIC KEY-----
60
$pubKeyContent
61
-----END PUBLIC KEY-----";
62
63
        $prikey1 = $timCloud->formatKey($priKeyContent, 'private');
64
        $pubkey1 = $timCloud->formatKey($pubKeyContent, 'public');
65
66
        $prikey2 = $timCloud->formatKey($openSSLPrivateKey, 'private');
67
        $pubkey2 = $timCloud->formatKey($openSSLPublicKey, 'public');
68
69
        $this->assertSame($openSSLPrivateKey, $prikey1);
70
        $this->assertSame($openSSLPublicKey, $pubkey1);
71
        $this->assertSame($openSSLPrivateKey, $prikey2);
72
        $this->assertSame($openSSLPublicKey, $pubkey2);
73
    }
74
75
    public function testRequestApi()
76
    {
77
        $t = $this->timCloud();
78
        $t->offsetSet('im', function ()  {
79
            $m = Mockery::mock('im');
80
            $m->shouldReceive('handle')->withAnyArgs()->andReturn(new ResponseBag([
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'handle'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

80
            $m->/** @scrutinizer ignore-call */ 
81
                shouldReceive('handle')->withAnyArgs()->andReturn(new ResponseBag([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
81
                'ActionStatus' => 'OK'
82
            ], [
83
                'content-type' => 'application/json'
84
            ]));
85
            return $m;
86
        });
87
88
        $c = $t->request(API::DIRTY_WORDS_GET);
89
        $this->assertSame('OK', $c->getContent('ActionStatus'));
90
    }
91
92
    public function timCloud()
93
    {
94
        return new TimCloud([
95
            'sdkappid'   => phpunit_env('sdk_appid', '1400xxxxxx'),
96
            'identifier' => phpunit_env('identifier', 'common_user'),
97
            'prikey'     => phpunit_env('private_key', 'openssl_private_key'),
98
            'pubkey'     => phpunit_env('public_key', 'openssl_public_key'),
99
        ], [
100
            'TLSSig' => function () {
101
                $m = Mockery::mock('TLSSig');
102
                $m->shouldReceive('genSig')->withAnyArgs()->andReturn('test usersig');
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'genSig'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

102
                $m->/** @scrutinizer ignore-call */ 
103
                    shouldReceive('genSig')->withAnyArgs()->andReturn('test usersig');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
103
                return $m;
104
            },
105
        ]);
106
    }
107
108
    public function tearDown()
109
    {
110
        Mockery::close();
111
    }
112
}
113