Skip to content

Commit

Permalink
refactor(tests): refactor create_response to response
Browse files Browse the repository at this point in the history
- Refactored all occurrences of `create_response` to `response` for consistency and clarity.
  • Loading branch information
guanguans committed Jul 9, 2024
1 parent 4aa5603 commit 96c3387
Show file tree
Hide file tree
Showing 32 changed files with 62 additions and 62 deletions.
4 changes: 2 additions & 2 deletions tests/AnPush/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

expect($client)
->mock([
create_response('{"msg":"success","code":200,"data":{"msgIds":[{"channelId":"94412","msgId":1715333937401}]}}'),
create_response('{"msg":"Token not found","code":10006}'),
response('{"msg":"success","code":200,"data":{"msgIds":[{"channelId":"94412","msgId":1715333937401}]}}'),
response('{"msg":"Token not found","code":10006}'),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
4 changes: 2 additions & 2 deletions tests/Bark/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@

expect($client)
->mock([
create_response('{"code":200,"message":"success","timestamp":1708331409}'),
create_response(
response('{"code":200,"message":"success","timestamp":1708331409}'),
response(
'{"code":400,"message":"failed to get device token: failed to get [yetwhxBm7wCBSUTjeqh] device token from database","timestamp":1708331590}',
400,
),
Expand Down
4 changes: 2 additions & 2 deletions tests/Chanify/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
beforeEach(function (): void {
$authenticator = new Authenticator('CICwhbIGEiJBQVdIWlVKS1JORVY0UlVETFZYVVpRTlNLTlVZVlZPT1JFIgIIAQ.orHlBVavQPrY-ZP3eqQKDgjyTtNdZPdNYV6lpAx8');
$this->client = (new Client($authenticator))->mock([
create_response('{"request-uid":"03fe6123-2098-4af8-a210-658010a69d9c"}'),
create_response('{"res":400,"msg":"bad request"}', 400),
response('{"request-uid":"03fe6123-2098-4af8-a210-658010a69d9c"}'),
response('{"res":400,"msg":"bad request"}', 400),
]);
});

Expand Down
4 changes: 2 additions & 2 deletions tests/DingTalk/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
'SECc32bb7345c0f73da2b9786f0f7dd5083bd768a29b82e6d460149d730eee51730',
);
$this->client = (new Client($authenticator))->mock([
create_response('{"errcode":0,"errmsg":"ok"}'),
create_response('{"errcode":300005,"errmsg":"token is not exist"}'),
response('{"errcode":0,"errmsg":"ok"}'),
response('{"errcode":300005,"errmsg":"token is not exist"}'),
]);
});

Expand Down
4 changes: 2 additions & 2 deletions tests/Discord/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@

expect($client)
->mock([
create_response('', 204),
create_response('{"message": "Invalid Webhook Token", "code": 50027}', 401),
response('', 204),
response('{"message": "Invalid Webhook Token", "code": 50027}', 401),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
2 changes: 1 addition & 1 deletion tests/Gitter/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

expect($client)
->mock([
create_response(faker()->text()),
response(faker()->text()),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
2 changes: 1 addition & 1 deletion tests/GoogleChat/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

expect($client)
->mock([
create_response(faker()->text()),
response(faker()->text()),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
4 changes: 2 additions & 2 deletions tests/IGot/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

expect($client)
->mock([
create_response('{"ret":0,"data":{"id":"65d31d11adda140033fc8c17"},"errMsg":"发送成功"}'),
create_response('{"ret":201,"data":{},"errMsg":"请使用系统分配的有效key"}'),
response('{"ret":0,"data":{"id":"65d31d11adda140033fc8c17"},"errMsg":"发送成功"}'),
response('{"ret":201,"data":{},"errMsg":"请使用系统分配的有效key"}'),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
4 changes: 2 additions & 2 deletions tests/Lark/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
'WeqWRCyD9pawyIPGqldUYe',
);
$this->client = (new Client($authenticator))->mock([
create_response('{"StatusCode":0,"StatusMessage":"success","code":0,"data":{},"msg":"success"}'),
create_response('{"code":19001,"data":{},"msg":"param invalid: incoming webhook access token invalid"}'),
response('{"StatusCode":0,"StatusMessage":"success","code":0,"data":{},"msg":"success"}'),
response('{"code":19001,"data":{},"msg":"param invalid: incoming webhook access token invalid"}'),
]);
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Mattermost/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
// ->baseUri('https://guanguans.cloud.mattermost.com')
->baseUri('Your mattermost server url.')
->mock([
create_response(faker()->text()),
response(faker()->text()),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
2 changes: 1 addition & 1 deletion tests/MicrosoftTeams/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@

expect($client)
->mock([
create_response(faker()->text()),
response(faker()->text()),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
2 changes: 1 addition & 1 deletion tests/NowPush/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
beforeEach(function (): void {
$authenticator = new Authenticator('vpNVue4teSl93ijHBVT6sDT4sHLP7OMTzFCfdQb0QxLYvL');
$this->client = (new Client($authenticator))->mock([
create_response(faker()->text()),
response(faker()->text()),
]);
});

Expand Down
6 changes: 3 additions & 3 deletions tests/Ntfy/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@

expect($client)
->mock([
create_response('{"id":"ChjDFVOPqaBK","time":1708335367,"expires":1708378567,"event":"message","topic":"guanguans","title":"This is title.","message":"This is message.","priority":1,"tags":["tag1","tag2"],"click":"https://example.com","icon":"https://www.guanguans.cn","attachment":{"name":"file.jpg","url":"https://www.guanguans.cn"}}'),
create_response(
response('{"id":"ChjDFVOPqaBK","time":1708335367,"expires":1708378567,"event":"message","topic":"guanguans","title":"This is title.","message":"This is message.","priority":1,"tags":["tag1","tag2"],"click":"https://example.com","icon":"https://www.guanguans.cn","attachment":{"name":"file.jpg","url":"https://www.guanguans.cn"}}'),
response(
'{"code":40035,"http":400,"error":"invalid request: anonymous phone calls are not allowed","link":"https://ntfy.sh/docs/publish/#phone-calls"}',
400,
),
create_response('{"code":40003,"http":400,"error":"delayed e-mail notifications are not supported"}', 400),
response('{"code":40003,"http":400,"error":"delayed e-mail notifications are not supported"}', 400),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
2 changes: 1 addition & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function fixtures_path(string $path = ''): string
*
* @param null|mixed $body
*/
function create_response(
function response(
$body = null,
int $status = 200,
array $headers = [],
Expand Down
4 changes: 2 additions & 2 deletions tests/Push/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
beforeEach(function (): void {
$authenticator = new Authenticator('5db80e8a-1f9b-4f98-929a-75892cedc');
$this->client = (new Client($authenticator))->mock([
create_response('{"success":true,"responses":[{"success":true,"message":"Message send to device"},{"success":true,"message":"Message send to device"}]}'),
create_response('{"success":false,"message":"Invalid API key, authentication failed"}', 401),
response('{"success":true,"responses":[{"success":true,"message":"Message send to device"},{"success":true,"message":"Message send to device"}]}'),
response('{"success":false,"message":"Invalid API key, authentication failed"}', 401),
]);
});

Expand Down
4 changes: 2 additions & 2 deletions tests/PushBullet/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

expect($client)
->mock([
create_response('{"active":true,"iden":"ujEkbcC7F0esjuPmSKdbKC","created":1709867052.256945,"modified":1709867052.256945,"type":"link","dismissed":false,"direction":"self","sender_iden":"ujEkbcC7F0e","sender_email":"[email protected]","sender_email_normalized":"[email protected]","sender_name":"姚明明","receiver_iden":"ujEkbcC7F0e","receiver_email":"[email protected]","receiver_email_normalized":"[email protected]","title":"This is title.","body":"This is body.","url":"https://github.com/guanguans/notify"}'),
create_response('{"error":{"code":"invalid_access_token","type":"invalid_request","message":"Access token is missing or invalid.","cat":"(=^・ω・^)y="},"error_code":"invalid_access_token"}', 401),
response('{"active":true,"iden":"ujEkbcC7F0esjuPmSKdbKC","created":1709867052.256945,"modified":1709867052.256945,"type":"link","dismissed":false,"direction":"self","sender_iden":"ujEkbcC7F0e","sender_email":"[email protected]","sender_email_normalized":"[email protected]","sender_name":"姚明明","receiver_iden":"ujEkbcC7F0e","receiver_email":"[email protected]","receiver_email_normalized":"[email protected]","title":"This is title.","body":"This is body.","url":"https://github.com/guanguans/notify"}'),
response('{"error":{"code":"invalid_access_token","type":"invalid_request","message":"Access token is missing or invalid.","cat":"(=^・ω・^)y="},"error_code":"invalid_access_token"}', 401),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
4 changes: 2 additions & 2 deletions tests/PushDeer/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

expect($client)
->mock([
create_response('{"code":0,"content":{"result":["{\"counts\":1,\"logs\":[],\"success\":\"ok\"}","{\"counts\":1,\"logs\":[],\"success\":\"ok\"}"]}}'),
create_response(faker()->randomHtml(), 500),
response('{"code":0,"content":{"result":["{\"counts\":1,\"logs\":[],\"success\":\"ok\"}","{\"counts\":1,\"logs\":[],\"success\":\"ok\"}"]}}'),
response(faker()->randomHtml(), 500),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
4 changes: 2 additions & 2 deletions tests/PushPlus/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

expect($client)
->mock([
create_response('{"code":200,"msg":"请求成功","data":"aab34a37c1ff49ef8087cb3cd2c0d1ff","count":null}'),
create_response('{"code":903,"msg":"无效的用户token","data":null}'),
response('{"code":200,"msg":"请求成功","data":"aab34a37c1ff49ef8087cb3cd2c0d1ff","count":null}'),
response('{"code":903,"msg":"无效的用户token","data":null}'),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
6 changes: 3 additions & 3 deletions tests/Pushback/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
beforeEach(function (): void {
$authenticator = new Authenticator('at_b33c2bFrKAPmQr5-BaG');
$this->client = (new Client($authenticator))->mock([
create_response('0'),
create_response('This is reply message.'),
create_response(
response('0'),
response('This is reply message.'),
response(
<<<'error'
{
"errors": [
Expand Down
4 changes: 2 additions & 2 deletions tests/Pushover/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@

expect($client)
->mock([
create_response('{"status":1,"request":"a84b20eb-b69e-4687-83d1-bab8ee2d0e40"}'),
create_response(
response('{"status":1,"request":"a84b20eb-b69e-4687-83d1-bab8ee2d0e40"}'),
response(
'{"token":"invalid","errors":["application token is invalid, see https://pushover.net/api"],"status":0,"request":"5c4487c0-a61a-497e-9205-3441a99471b0"}',
400,
),
Expand Down
4 changes: 2 additions & 2 deletions tests/QQ/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@

expect($client)
->mock([
create_response('{"id":"08efdfa1b3e1d4d6e246109fbe8702383048e4d0ccae06","channel_id":"4316959","guild_id":"5099581822453968879","content":"This is content.","timestamp":"2024-02-19T18:07:32+08:00","tts":false,"mention_everyone":false,"author":{"id":"7938900097687957410","username":"","avatar":"","bot":true},"pinned":false,"type":0,"flags":0,"seq_in_channel":"48"}'),
create_response(
response('{"id":"08efdfa1b3e1d4d6e246109fbe8702383048e4d0ccae06","channel_id":"4316959","guild_id":"5099581822453968879","content":"This is content.","timestamp":"2024-02-19T18:07:32+08:00","tts":false,"mention_everyone":false,"author":{"id":"7938900097687957410","username":"","avatar":"","bot":true},"pinned":false,"type":0,"flags":0,"seq_in_channel":"48"}'),
response(
'{"message":"Token错误","code":11243,"err_code":40012002,"trace_id":"b363de10b4c8893a382b8b9d6d07c615"}',
401,
),
Expand Down
4 changes: 2 additions & 2 deletions tests/RocketChat/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@

expect($client)
->mock([
create_response('{"success":true}'),
create_response('{"success":false,"error":"Invalid integration id or token provided."}'),
response('{"success":true}'),
response('{"success":false,"error":"Invalid integration id or token provided."}'),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
4 changes: 2 additions & 2 deletions tests/ServerChan/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

expect($client)
->mock([
create_response('{"code":0,"message":"","data":{"pushid":"156157448","readkey":"SCTRd7BkgAHn6XG","error":"SUCCESS","errno":0}}'),
create_response(
response('{"code":0,"message":"","data":{"pushid":"156157448","readkey":"SCTRd7BkgAHn6XG","error":"SUCCESS","errno":0}}'),
response(
'{"message":"[AUTH]\u9519\u8bef\u7684Key","code":40001,"info":"\u9519\u8bef\u7684Key","args":[null],"scode":461}',
400,
),
Expand Down
4 changes: 2 additions & 2 deletions tests/ShowdocPush/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

expect($client)
->mock([
create_response('{"error_code":0,"error_message":"ok"}'),
create_response('{"error_code":10103,"error_message":"url\u6216token\u4e0d\u6b63\u786e"}'),
response('{"error_code":0,"error_message":"ok"}'),
response('{"error_code":10103,"error_message":"url\u6216token\u4e0d\u6b63\u786e"}'),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
4 changes: 2 additions & 2 deletions tests/SimplePush/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@

expect($client)
->mock([
create_response('{"status":"OK"}'),
create_response('', 406),
response('{"status":"OK"}'),
response('', 406),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
4 changes: 2 additions & 2 deletions tests/Slack/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@

expect($client)
->mock([
create_response('ok'),
create_response('invalid_token', 403),
response('ok'),
response('invalid_token', 403),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
4 changes: 2 additions & 2 deletions tests/Telegram/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
beforeEach(function (): void {
$authenticator = new Authenticator('6825137102:AAHQvvBpsoJVs-lQSKjZNLELMmpzQ50p');
$this->client = (new Client($authenticator))->mock([
create_response('{"ok":true,"result":{"message_id":5,"from":{"id":6825137102,"is_bot":true,"first_name":"guanguansbot","username":"guanguand_bot"},"chat":{"id":6173634402,"first_name":"guanguans","type":"private"},"date":1708397315,"text":"This is text","entities":[{"offset":0,"length":12,"type":"bold"}]}}'),
create_response('{"ok":false,"error_code":401,"description":"Unauthorized"}', 401),
response('{"ok":true,"result":{"message_id":5,"from":{"id":6825137102,"is_bot":true,"first_name":"guanguansbot","username":"guanguand_bot"},"chat":{"id":6173634402,"first_name":"guanguans","type":"private"},"date":1708397315,"text":"This is text","entities":[{"offset":0,"length":12,"type":"bold"}]}}'),
response('{"ok":false,"error_code":401,"description":"Unauthorized"}', 401),
]);
});

Expand Down
4 changes: 2 additions & 2 deletions tests/WPush/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

expect($client)
->mock([
create_response('{"code":0,"message":"success","data":"50285451654725632"}'),
create_response('{"code":401,"message":"API Key错误","data":null}'),
response('{"code":0,"message":"success","data":"50285451654725632"}'),
response('{"code":401,"message":"API Key错误","data":null}'),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
8 changes: 4 additions & 4 deletions tests/WeWork/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
beforeEach(function (): void {
$authenticator = new Authenticator('73a3d5a3-ceff-4da8-bcf3-ff5891778');
$this->client = (new Client($authenticator))->mock([
create_response('{"errcode":0,"errmsg":"ok"}'),
create_response('{"errcode":93000,"errmsg":"invalid webhook url, hint: [1708397705432012366598976], from ip: 218.72.126.124, more info at https://open.work.weixin.qq.com/devtool/query?e=93000"}'),
response('{"errcode":0,"errmsg":"ok"}'),
response('{"errcode":93000,"errmsg":"invalid webhook url, hint: [1708397705432012366598976], from ip: 218.72.126.124, more info at https://open.work.weixin.qq.com/devtool/query?e=93000"}'),
]);
});

Expand All @@ -43,8 +43,8 @@

expect($this->client)
->mock([
create_response('{"errcode":0,"errmsg":"ok","type":"file","media_id":"3h9Ps2X6_-HSlzxXyRJibTGRREIkBPgtZIG0dPRJFlOl5bKroWVHXaTQQV6sSPz5h","created_at":"1709387991"}'),
create_response('{"errcode":40058,"errmsg":"invalid param \'key\', hint: [1709388087101961098685339], from ip: 211.90.236.131, more info at https://open.work.weixin.qq.com/devtool/query?e=40058"}'),
response('{"errcode":0,"errmsg":"ok","type":"file","media_id":"3h9Ps2X6_-HSlzxXyRJibTGRREIkBPgtZIG0dPRJFlOl5bKroWVHXaTQQV6sSPz5h","created_at":"1709387991"}'),
response('{"errcode":40058,"errmsg":"invalid param \'key\', hint: [1709388087101961098685339], from ip: 211.90.236.131, more info at https://open.work.weixin.qq.com/devtool/query?e=40058"}'),
])
->assertCanSendMessage($uploadMediaMessage);
})->group(__DIR__, __FILE__);
Expand Down
4 changes: 2 additions & 2 deletions tests/XiZhi/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
beforeEach(function (): void {
$authenticator = new Authenticator('XZf0db6d069509ec52afc1f3493b76e');
$this->client = (new Client($authenticator))->mock([
create_response('{"code":200,"msg":"推送成功"}'),
create_response('{"code":10000,"msg":"用户不存在"}'),
response('{"code":200,"msg":"推送成功"}'),
response('{"code":10000,"msg":"用户不存在"}'),
]);
});

Expand Down
4 changes: 2 additions & 2 deletions tests/YiFengChuanHua/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

expect($client)
->mock([
create_response('{"code":0,"message":"请求成功","data":{"messageIdList":["1341726823083966464"]}}'),
create_response('{"code":46001,"message":"通道不存在","data":null}'),
response('{"code":0,"message":"请求成功","data":{"messageIdList":["1341726823083966464"]}}'),
response('{"code":46001,"message":"通道不存在","data":null}'),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
4 changes: 2 additions & 2 deletions tests/Zulip/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
$this->client = (new Client($authenticator))
->baseUri('https://xxx.zulipchat.com/')
->mock([
create_response('{"result":"success","msg":"","id":1740849}'),
create_response('{"result":"error","msg":"Malformed API key","code":"UNAUTHORIZED"}', 401),
response('{"result":"success","msg":"","id":1740849}'),
response('{"result":"error","msg":"Malformed API key","code":"UNAUTHORIZED"}', 401),
]);
});

Expand Down

0 comments on commit 96c3387

Please sign in to comment.