Modify: 自动化测试

新增:
- Afadian.php
- NeteaseCloud.php

修改:
- .gitignore

Signed-off-by: XiaoLFeng <gm@x-lf.cn>
This commit is contained in:
筱锋xiao_lfeng 2023-07-24 15:56:50 +08:00
parent 544ecf471c
commit 944317212f
3 changed files with 95 additions and 1 deletions

1
.gitignore vendored
View File

@ -13,5 +13,4 @@ npm-debug.log
yarn-error.log yarn-error.log
/.idea /.idea
/.vscode /.vscode
/tests/
/public/ /public/

55
tests/Feature/Afadian.php Normal file
View File

@ -0,0 +1,55 @@
<?php
/*
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
* 开发开源遵循 MIT 许可,若需商用请联系开发者
* https://www.x-lf.com/
*/
namespace Tests\Feature;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class Afadian extends TestCase
{
public function test_example()
{
// 从数据库获取数据
$result = DB::table('info')
->get()
->toArray();
$userID = $result[20]->data;
$token = $result[21]->data;
$time = time();
$params = [
'page' => 1,
'per_page' => 50,
];
$sign = md5($token . 'params' . json_encode($params) . 'ts' . $time . 'user_id' . $userID);
$data = [
'query' => [
'user_id' => $userID,
'params' => json_encode($params),
'ts' => $time,
'sign' => $sign,
],
];
$client = new Client(['verify' => false]);
try {
$response = $client->get('https://afdian.net/api/open/query-sponsor', $data);
var_dump(json_decode($response->getBody()->getContents()));
$this->assertTrue(true, "可以访问");
} catch (GuzzleException $e) {
echo $e;
$this->fail("发生错误");
}
}
}

View File

@ -0,0 +1,40 @@
<?php
/*
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
* 开发开源遵循 MIT 许可,若需商用请联系开发者
* https://www.x-lf.com/
*/
namespace Tests\Feature;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Tests\TestCase;
class NeteaseCloud extends TestCase
{
public function test_example()
{
// 从数据库获取数据
$data = [
'query' => [
'id' => '32459197',
'limit' => 20,
],
];
$client = new Client(['verify' => false]);
try {
$response = $client->get('https://netease.api.x-lf.cn/artist/songs', $data);
print_r(json_decode($response->getBody()->getContents()));
$this->assertTrue(true, "可以访问");
} catch (GuzzleException $e) {
echo $e;
$this->fail("发生错误");
}
}
}