-
Notifications
You must be signed in to change notification settings - Fork 1
/
BaseTestCase.php
118 lines (112 loc) · 3.31 KB
/
BaseTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace Tests;
/**
* BaseTestCase
*
* @author Pu ShaoWei <[email protected]>
* @date 2017/12/7
* @version 1.0
* @license MIT
*/
class BaseTestCase extends \PHPUnit\Framework\TestCase
{
const DB_TEST_TABLE = 'test';
const DB_PRACTICE = 'practice';
/**
* BaseTestCase constructor.
*
* @param null $name
* @param array $data
* @param string $dataName
*/
public function __construct($name = null, array $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);
require dirname(__DIR__) . '/vendor/autoload.php';
}
/**
* 获取初始化配置
*
* @return array
*/
public function getDefaultConfig()
{
return array (
/**
* SMART DATABASES
*/
'smart' => array (
'host' => "127.0.0.1",
'write' => array (
'port' => 3307,
'password' => 'smart_master'
),
'read' => array (
array (
'port' => 3308,
'password' => 'smart_slave_one'
),
array (
'port' => 3309,
'password' => 'smart_slave_two'
),
),
'driver' => 'mysql',
'database' => "db_master_test",
'username' => "root",
'password' => "master_test",
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => 'smart_db_',
'strict' => false,
'engine' => null,
),
/**
* BIZ DATABASES
*/
'biz' => array (
'host' => "127.0.0.1",
'port' => 3310,
'password' => 'biz_master',
'driver' => 'mysql',
'database' => 'db_biz_test',
'username' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => 'biz_',
'strict' => false,
'engine' => null,
),
);
}
/**
* 获取随机字符串
*
* @param int $length
* @param string $type
* @param int $convert
* @return string
*/
function random($length = 6, $type = 'string', $convert = 0)
{
$config = array (
'number' => '1234567890',
'letter' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'string' => 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789',
'all' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
);
if (!isset($config[$type])) {
$type = 'string';
}
$string = $config[$type];
$code = '';
$strlen = strlen($string) - 1;
for ($i = 0; $i < $length; $i++) {
$code .= $string{mt_rand(0, $strlen)};
}
if (!empty($convert)) {
$code = ($convert > 0) ? strtoupper($code) : strtolower($code);
}
return $code;
}
}