|
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)); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
$this->http = new Http($this->accessToken); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
} |
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:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.