Skip to content

Commit

Permalink
chore(tests): refactor ClientTest setup and teardown methods
Browse files Browse the repository at this point in the history
- Refactor setUpBeforeClass and tearDownAfterClass methods in TestCase class
- Remove unnecessary parent calls in setUp and tearDown methods
  • Loading branch information
guanguans committed Mar 7, 2024
1 parent d415cd5 commit f62ffb8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
7 changes: 1 addition & 6 deletions tests/GoogleChat/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@
use function Pest\Faker\faker;

it('can send message', function (): void {
$authenticator = new Authenticator(
'spaceId',
'key',
'token',
'threadKey',
);
$authenticator = new Authenticator('spaceId', 'key', 'token', 'threadKey');
$client = new Client($authenticator);
$message = Message::make([
'text' => 'This is text.',
Expand Down
2 changes: 1 addition & 1 deletion tests/Mattermost/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

expect($client)
// ->baseUri('https://guanguans.cloud.mattermost.com')
->baseUri('Your Mattermost server URL.')
->baseUri('Your mattermost server url.')
->mock([
create_response(faker()->text()),
])
Expand Down
5 changes: 4 additions & 1 deletion tests/Ntfy/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
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('{"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":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),
])
->assertCanSendMessage($message);
Expand Down
5 changes: 4 additions & 1 deletion tests/Pushover/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
expect($client)
->mock([
create_response('{"status":1,"request":"a84b20eb-b69e-4687-83d1-bab8ee2d0e40"}'),
create_response('{"token":"invalid","errors":["application token is invalid, see https://pushover.net/api"],"status":0,"request":"5c4487c0-a61a-497e-9205-3441a99471b0"}', 400),
create_response(
'{"token":"invalid","errors":["application token is invalid, see https://pushover.net/api"],"status":0,"request":"5c4487c0-a61a-497e-9205-3441a99471b0"}',
400
),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
5 changes: 4 additions & 1 deletion tests/QQ/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@
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('{"message":"Token错误","code":11243,"err_code":40012002,"trace_id":"b363de10b4c8893a382b8b9d6d07c615"}', 401),
create_response(
'{"message":"Token错误","code":11243,"err_code":40012002,"trace_id":"b363de10b4c8893a382b8b9d6d07c615"}',
401
),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
5 changes: 4 additions & 1 deletion tests/ServerChan/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
expect($client)
->mock([
create_response('{"code":0,"message":"","data":{"pushid":"156157448","readkey":"SCTRd7BkgAHn6XG","error":"SUCCESS","errno":0}}'),
create_response('{"message":"[AUTH]\u9519\u8bef\u7684Key","code":40001,"info":"\u9519\u8bef\u7684Key","args":[null],"scode":461}', 400),
create_response(
'{"message":"[AUTH]\u9519\u8bef\u7684Key","code":40001,"info":"\u9519\u8bef\u7684Key","args":[null],"scode":461}',
400
),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);
12 changes: 2 additions & 10 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,18 @@ class TestCase extends \PHPUnit\Framework\TestCase
/**
* This method is called before the first test of this test class is run.
*/
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
}
public static function setUpBeforeClass(): void {}

/**
* This method is called after the last test of this test class is run.
*/
public static function tearDownAfterClass(): void
{
parent::tearDownAfterClass();
}
public static function tearDownAfterClass(): void {}

/**
* This method is called before each test.
*/
protected function setUp(): void
{
parent::setUp();
// \DG\BypassFinals::enable();
}

Expand All @@ -55,7 +48,6 @@ protected function setUp(): void
*/
protected function tearDown(): void
{
parent::tearDown();
$this->finish();
\Mockery::close();
}
Expand Down

0 comments on commit f62ffb8

Please sign in to comment.