chore: code refactor via rector
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Exception;
|
||||
use App\Http\Controllers\WebhookController;
|
||||
use App\NotifyMe;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
@@ -17,6 +18,7 @@ class TestNotifier
|
||||
|
||||
class NotifyMeTest extends TestCase
|
||||
{
|
||||
public $notifier;
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -25,7 +27,7 @@ class NotifyMeTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_sends_telegram_notification_successfully()
|
||||
public function it_sends_telegram_notification_successfully(): void
|
||||
{
|
||||
Config::set('app.notify_tg_bot_token', 'test_bot_token');
|
||||
Config::set('app.notify_tg_chat_id', 'test_chat_id');
|
||||
@@ -40,18 +42,16 @@ class NotifyMeTest extends TestCase
|
||||
$result = $this->notifier->sendTelegramNotification('Test message');
|
||||
|
||||
$this->assertTrue($result);
|
||||
Http::assertSent(function ($request) {
|
||||
return $request->url() === 'https://api.telegram.org/bottest_bot_token/sendMessage' &&
|
||||
$request['chat_id'] === 'test_chat_id' &&
|
||||
$request['text'] === 'Test message' &&
|
||||
$request['parse_mode'] === 'HTML';
|
||||
});
|
||||
Http::assertSent(fn(array $request): bool => $request->url() === 'https://api.telegram.org/bottest_bot_token/sendMessage' &&
|
||||
$request['chat_id'] === 'test_chat_id' &&
|
||||
$request['text'] === 'Test message' &&
|
||||
$request['parse_mode'] === 'HTML');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_when_bot_token_is_not_configured()
|
||||
public function it_fails_when_bot_token_is_not_configured(): void
|
||||
{
|
||||
Config::set('app.notify_tg_bot_token', null);
|
||||
Config::set('app.notify_tg_bot_token');
|
||||
Config::set('app.notify_tg_chat_id', 'test_chat_id');
|
||||
|
||||
Log::shouldReceive('error')
|
||||
@@ -64,10 +64,10 @@ class NotifyMeTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_when_chat_id_is_not_configured()
|
||||
public function it_fails_when_chat_id_is_not_configured(): void
|
||||
{
|
||||
Config::set('app.notify_tg_bot_token', 'test_bot_token');
|
||||
Config::set('app.notify_tg_chat_id', null);
|
||||
Config::set('app.notify_tg_chat_id');
|
||||
|
||||
Log::shouldReceive('error')
|
||||
->once()
|
||||
@@ -79,7 +79,7 @@ class NotifyMeTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_handles_http_errors_gracefully()
|
||||
public function it_handles_http_errors_gracefully(): void
|
||||
{
|
||||
Config::set('app.notify_tg_bot_token', 'test_bot_token');
|
||||
Config::set('app.notify_tg_chat_id', 'test_chat_id');
|
||||
@@ -98,14 +98,14 @@ class NotifyMeTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_handles_network_exceptions()
|
||||
public function it_handles_network_exceptions(): void
|
||||
{
|
||||
Config::set('app.notify_tg_bot_token', 'test_bot_token');
|
||||
Config::set('app.notify_tg_chat_id', 'test_chat_id');
|
||||
|
||||
Http::fake([
|
||||
'https://api.telegram.org/bottest_bot_token/sendMessage' => Http::throw(function ($request) {
|
||||
throw new \Exception('Network error');
|
||||
'https://api.telegram.org/bottest_bot_token/sendMessage' => Http::throw(function ($request): void {
|
||||
throw new Exception('Network error');
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -118,7 +118,7 @@ class NotifyMeTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_sends_messages_with_html_parsing_mode()
|
||||
public function it_sends_messages_with_html_parsing_mode(): void
|
||||
{
|
||||
Config::set('app.notify_tg_bot_token', 'test_bot_token');
|
||||
Config::set('app.notify_tg_chat_id', 'test_chat_id');
|
||||
@@ -133,14 +133,12 @@ class NotifyMeTest extends TestCase
|
||||
$htmlMessage = '<b>Bold text</b> and <i>italic text</i>';
|
||||
$this->notifier->sendTelegramNotification($htmlMessage);
|
||||
|
||||
Http::assertSent(function ($request) use ($htmlMessage) {
|
||||
return $request['parse_mode'] === 'HTML' &&
|
||||
$request['text'] === $htmlMessage;
|
||||
});
|
||||
Http::assertSent(fn(array $request): bool => $request['parse_mode'] === 'HTML' &&
|
||||
$request['text'] === $htmlMessage);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_be_used_in_controller_context()
|
||||
public function it_can_be_used_in_controller_context(): void
|
||||
{
|
||||
Config::set('app.notify_tg_bot_token', 'test_bot_token');
|
||||
Config::set('app.notify_tg_chat_id', 'test_chat_id');
|
||||
|
||||
Reference in New Issue
Block a user