Completed
Push — master ( a3c7a7...bd72ff )
by Carlos
02:47
created

TestBase   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 42
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 25 1
1
<?php
2
/**
3
 * TestBase.php
4
 *
5
 * Part of Overtrue\Wechat\Test
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    a9396 <[email protected]>
11
 * @copyright 2015 a939638621 <[email protected]>
12
 * @link      https://github.com/a939638621
13
 */
14
15
namespace Overtrue\Wechat\Test;
16
17
18
use Overtrue\Wechat\Shop\Config;
19
use Overtrue\Wechat\Shop\AccessToken;
20
use Overtrue\Wechat\Http;
21
use Symfony\Component\Yaml\Yaml;
22
23
class TestBase extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @var Config
27
     */
28
    protected $config;
29
30
    /**
31
     * @var accessToken
32
     */
33
    protected $accessToken;
34
    /**
35
     * @var HTTP
36
     */
37
    protected $http;
38
39
    protected function setUp()
40
    {
41
        $config = __DIR__.DIRECTORY_SEPARATOR.'Config'.DIRECTORY_SEPARATOR.'Config.yml';
42
        $cert = __DIR__.DIRECTORY_SEPARATOR.'Cert'.DIRECTORY_SEPARATOR;
43
44
        //yml::载入配置
45
        $data = Yaml::parse(file_get_contents($config));
46
47
        $this->config = new Config($data['appId'],$data['appSecret'],$data['debug']);
48
        $this->config->setMessageConfig($data['token'],$data['encodingAESKey']);
49
        $this->config->setPayConfig($data['mchId'],$data['mchId']);
50
51
        $data['clientCert'] = $cert.'apiclient_cert.pem';
52
        $data['clientKey'] = $cert.'apiclient_key.pem';
53
54
        file_put_contents($config,Yaml::dump($data));
0 ignored issues
show
Bug introduced by
It seems like $data defined by \Symfony\Component\Yaml\..._get_contents($config)) on line 45 can also be of type string; however, Symfony\Component\Yaml\Yaml::dump() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
55
56
        $data = Yaml::parse(file_get_contents($config));
57
58
        $this->config->setPEMConfig($data['clientCert'],$data['clientKey']);
59
60
        $this->accessToken = new AccessToken($this->config);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Overtrue\Wechat\Sho...essToken($this->config) of type object<Overtrue\Wechat\Shop\AccessToken> is incompatible with the declared type object<Overtrue\Wechat\Test\accessToken> of property $accessToken.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
61
62
        $this->http = new Http($this->accessToken);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Overtrue\Wechat\Http($this->accessToken) of type object<Overtrue\Wechat\Http> is incompatible with the declared type object<Overtrue\Wechat\Test\HTTP> of property $http.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
63
    }
64
}