Skip to content

Commit 4ea58c9

Browse files
committed
PHP版本升级
1 parent 024a3eb commit 4ea58c9

File tree

4 files changed

+49
-27
lines changed

4 files changed

+49
-27
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/composer.lock
22
/vendor
3-
/.idea
3+
/.idea
4+
/.phpunit.result.cache
5+
/phpunit.xml

composer.json

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
{
2-
"type": "library",
3-
"name": "codeages/rate-limiter",
4-
"description": "Rate Limiting Library With Token Bucket Algorithm",
5-
"require": {
6-
"php": ">=5.3"
7-
},
8-
"require-dev": {
9-
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.0"
10-
},
11-
"suggest": {
12-
"ext-redis": "^2.2"
13-
},
14-
"license": "MIT",
15-
"authors": [
16-
{
17-
"name": "Codeages Team",
18-
"email": "[email protected]"
19-
}
20-
],
21-
"autoload": {
22-
"psr-4": {
23-
"Codeages\\RateLimiter\\": "src/"
24-
}
2+
"type": "library",
3+
"name": "codeages/rate-limiter",
4+
"description": "Rate Limiting Library With Token Bucket Algorithm",
5+
"require": {
6+
"php": ">=7.3"
7+
},
8+
"require-dev": {
9+
"phpunit/phpunit": "^8.5"
10+
},
11+
"suggest": {
12+
"ext-redis": "^2.2",
13+
"ext-pdo": "*"
14+
},
15+
"license": "MIT",
16+
"authors": [
17+
{
18+
"name": "Codeages Team",
19+
"email": "[email protected]"
2520
}
21+
],
22+
"autoload": {
23+
"psr-4": {
24+
"Codeages\\RateLimiter\\": "src/"
25+
}
26+
}
2627
}

phpunit.xml.dist

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
convertWarningsToExceptions = "true"
1111
processIsolation = "false"
1212
stopOnFailure = "false"
13-
syntaxCheck = "false"
1413
bootstrap = "vendor/autoload.php" >
1514

1615
<php>

tests/RateLimitTest.php renamed to tests/RateLimiterTest.php

+22-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public function testCheckRedis()
1818

1919
public function testCheckMySQLPDO()
2020
{
21-
$pdo = new PDO(getenv('MYSQL_DSN'), getenv('MYSQL_USER'), getenv('MYSQL_MYSQL_PASSWORD'));
21+
$pdo = new PDO(getenv('MYSQL_DSN'), getenv('MYSQL_USER'), getenv('MYSQL_PASSWORD'));
22+
$this->createMysqlTable($pdo);
2223
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
2324
$storage = new \Codeages\RateLimiter\Storage\MySQLPDOStorage($pdo);
2425
$this->check($storage);
@@ -38,7 +39,8 @@ public function testUpdateAllowanceRedis()
3839

3940
public function testUpdateAllowanceMySQLPDO()
4041
{
41-
$pdo = new PDO(getenv('MYSQL_DSN'), getenv('MYSQL_USER'), getenv('MYSQL_MYSQL_PASSWORD'));
42+
$pdo = new PDO(getenv('MYSQL_DSN'), getenv('MYSQL_USER'), getenv('MYSQL_PASSWORD'));
43+
$this->createMysqlTable($pdo);
4244
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
4345
$storage = new \Codeages\RateLimiter\Storage\MySQLPDOStorage($pdo);
4446
$this->updateAllowance($storage);
@@ -100,4 +102,22 @@ private function getRateLimiter(Storage $storage)
100102
{
101103
return new RateLimiter(self::NAME, self::MAX_REQUESTS, self::PERIOD, $storage);
102104
}
105+
106+
/**
107+
* @param PDO $pdo
108+
* @return void
109+
*/
110+
private function createMysqlTable(PDO $pdo): void
111+
{
112+
$pdo->exec("
113+
CREATE TABLE IF NOT EXISTS `ratelimit` (
114+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
115+
`_key` varchar(128) NOT NULL,
116+
`data` varchar(32) NOT NULL,
117+
`deadline` int(10) unsigned NOT NULL,
118+
PRIMARY KEY (`id`),
119+
UNIQUE KEY `_key` (`_key`)
120+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
121+
");
122+
}
103123
}

0 commit comments

Comments
 (0)