chore: 添加缺失的静态资源文件
添加多个前端界面所需的图片、字体、音频等静态资源文件,包括: - 管理员后台的图标、背景图、组件图片 - 移动端页面的商品图片、用户中心图片、活动图标 - 第三方库的示例图片和字体文件 - 浏览器兼容性配置文件 - 图标字体文件(eot、ttf、woff、woff2格式) 这些资源是前端界面正常显示所必需的,之前可能因版本控制忽略或遗漏而缺失。
This commit is contained in:
97
vendor/topthink/think-throttle/tests/CustomCacheTest.php
vendored
Normal file
97
vendor/topthink/think-throttle/tests/CustomCacheTest.php
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 自定义 cache 类
|
||||
*/
|
||||
namespace tests;
|
||||
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
use think\middleware\Throttle;
|
||||
|
||||
class CustomCache implements CacheInterface {
|
||||
protected $data = [];
|
||||
|
||||
public function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return isset($this->data[$key]) ? $this->data[$key] : $default;
|
||||
}
|
||||
|
||||
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool
|
||||
{
|
||||
$this->data[$key] = $value;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function delete(string $key): bool { return true; }
|
||||
public function clear(): bool { return true; }
|
||||
public function getMultiple(iterable $keys, mixed $default = null): iterable { return [];}
|
||||
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool { return true; }
|
||||
public function deleteMultiple(iterable $keys): bool { return true; }
|
||||
public function has(string $key): bool { return true; }
|
||||
}
|
||||
|
||||
class DummyCache implements CacheInterface {
|
||||
public function get($key, $default = null): mixed
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool { return true; }
|
||||
public function delete(string $key): bool { return true; }
|
||||
public function clear(): bool { return true; }
|
||||
public function getMultiple(iterable $keys, mixed $default = null): iterable { return [];}
|
||||
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool { return true; }
|
||||
public function deleteMultiple(iterable $keys): bool { return true; }
|
||||
public function has(string $key): bool { return true; }
|
||||
}
|
||||
|
||||
|
||||
class CustomCacheTest extends Base {
|
||||
|
||||
function visit(int $count): int
|
||||
{
|
||||
$allowCount = 0;
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$request = new \think\Request();
|
||||
$request->setMethod('GET');
|
||||
$request->setUrl('/');
|
||||
|
||||
$response = $this->get_response($request);
|
||||
if ($response->getCode() == 200) {
|
||||
$allowCount++;
|
||||
}
|
||||
}
|
||||
return $allowCount;
|
||||
}
|
||||
|
||||
function test_custom_cache()
|
||||
{
|
||||
$cache = new CustomCache();
|
||||
$config = $this->get_default_throttle_config();
|
||||
$config['visit_rate'] = '10/m';
|
||||
$config['key'] = function(Throttle $throttle, \think\Request $request) use ($cache) {
|
||||
$throttle->setCache($cache);
|
||||
return true;
|
||||
};
|
||||
|
||||
$this->set_throttle_config($config);
|
||||
|
||||
$this->assertEquals(10, $this->visit(200));
|
||||
}
|
||||
|
||||
function test_dummy_cache()
|
||||
{
|
||||
$cache = new DummyCache();
|
||||
$config = $this->get_default_throttle_config();
|
||||
$config['visit_rate'] = '10/m';
|
||||
$config['key'] = function(Throttle $throttle, \think\Request $request) use ($cache) {
|
||||
$throttle->setCache($cache);
|
||||
return true;
|
||||
};
|
||||
|
||||
$this->set_throttle_config($config);
|
||||
$this->assertEquals(200, $this->visit(200));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user