refactor: apply rector
Some checks are pending
tests / ci (push) Waiting to run

This commit is contained in:
Benjamin Nussbaum 2025-09-24 20:31:32 +02:00
parent c67a182cf2
commit b4b6286172
89 changed files with 672 additions and 666 deletions

View file

@ -8,14 +8,14 @@ use App\Notifications\BatteryLow;
use App\Notifications\Channels\WebhookChannel;
use Illuminate\Notifications\Messages\MailMessage;
test('battery low notification has correct via channels', function () {
test('battery low notification has correct via channels', function (): void {
$device = Device::factory()->create();
$notification = new BatteryLow($device);
expect($notification->via(new User()))->toBe(['mail', WebhookChannel::class]);
});
test('battery low notification creates correct mail message', function () {
test('battery low notification creates correct mail message', function (): void {
$device = Device::factory()->create([
'name' => 'Test Device',
'last_battery_voltage' => 3.0,
@ -29,7 +29,7 @@ test('battery low notification creates correct mail message', function () {
expect($mailMessage->viewData['device'])->toBe($device);
});
test('battery low notification creates correct webhook message', function () {
test('battery low notification creates correct webhook message', function (): void {
config([
'services.webhook.notifications.topic' => 'battery.low',
'app.name' => 'Test App',
@ -60,7 +60,7 @@ test('battery low notification creates correct webhook message', function () {
]);
});
test('battery low notification creates correct array representation', function () {
test('battery low notification creates correct array representation', function (): void {
$device = Device::factory()->create([
'name' => 'Test Device',
'last_battery_voltage' => 3.0,

View file

@ -11,13 +11,13 @@ use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Response;
use Illuminate\Notifications\Notification;
test('webhook channel returns null when no webhook url is configured', function () {
test('webhook channel returns null when no webhook url is configured', function (): void {
$client = Mockery::mock(Client::class);
$channel = new WebhookChannel($client);
$user = new class extends User
{
public function routeNotificationFor($driver, $notification = null)
public function routeNotificationFor($driver, $notification = null): null
{
return null; // No webhook URL configured
}
@ -30,13 +30,13 @@ test('webhook channel returns null when no webhook url is configured', function
expect($result)->toBeNull();
});
test('webhook channel throws exception when notification does not implement toWebhook', function () {
test('webhook channel throws exception when notification does not implement toWebhook', function (): void {
$client = Mockery::mock(Client::class);
$channel = new WebhookChannel($client);
$user = new class extends User
{
public function routeNotificationFor($driver, $notification = null)
public function routeNotificationFor($driver, $notification = null): string
{
return 'https://example.com/webhook';
}
@ -44,23 +44,23 @@ test('webhook channel throws exception when notification does not implement toWe
$notification = new class extends Notification
{
public function via($notifiable)
public function via($notifiable): array
{
return [];
}
};
expect(fn () => $channel->send($user, $notification))
expect(fn (): ?\GuzzleHttp\Psr7\Response => $channel->send($user, $notification))
->toThrow(Exception::class, 'Notification does not implement toWebhook method.');
});
test('webhook channel sends successful webhook request', function () {
test('webhook channel sends successful webhook request', function (): void {
$client = Mockery::mock(Client::class);
$channel = new WebhookChannel($client);
$user = new class extends User
{
public function routeNotificationFor($driver, $notification = null)
public function routeNotificationFor($driver, $notification = null): string
{
return 'https://example.com/webhook';
}
@ -86,13 +86,13 @@ test('webhook channel sends successful webhook request', function () {
expect($result)->toBe($expectedResponse);
});
test('webhook channel throws exception when response status is not successful', function () {
test('webhook channel throws exception when response status is not successful', function (): void {
$client = Mockery::mock(Client::class);
$channel = new WebhookChannel($client);
$user = new class extends User
{
public function routeNotificationFor($driver, $notification = null)
public function routeNotificationFor($driver, $notification = null): string
{
return 'https://example.com/webhook';
}
@ -107,17 +107,17 @@ test('webhook channel throws exception when response status is not successful',
->once()
->andReturn($errorResponse);
expect(fn () => $channel->send($user, $notification))
expect(fn (): ?\GuzzleHttp\Psr7\Response => $channel->send($user, $notification))
->toThrow(Exception::class, 'Webhook request failed with status code: 400');
});
test('webhook channel handles guzzle exceptions', function () {
test('webhook channel handles guzzle exceptions', function (): void {
$client = Mockery::mock(Client::class);
$channel = new WebhookChannel($client);
$user = new class extends User
{
public function routeNotificationFor($driver, $notification = null)
public function routeNotificationFor($driver, $notification = null): string
{
return 'https://example.com/webhook';
}
@ -130,6 +130,6 @@ test('webhook channel handles guzzle exceptions', function () {
->once()
->andThrow(new class extends Exception implements GuzzleException {});
expect(fn () => $channel->send($user, $notification))
expect(fn (): ?\GuzzleHttp\Psr7\Response => $channel->send($user, $notification))
->toThrow(Exception::class);
});

View file

@ -4,26 +4,26 @@ declare(strict_types=1);
use App\Notifications\Messages\WebhookMessage;
test('webhook message can be created with static method', function () {
test('webhook message can be created with static method', function (): void {
$message = WebhookMessage::create('test data');
expect($message)->toBeInstanceOf(WebhookMessage::class);
});
test('webhook message can be created with constructor', function () {
test('webhook message can be created with constructor', function (): void {
$message = new WebhookMessage('test data');
expect($message)->toBeInstanceOf(WebhookMessage::class);
});
test('webhook message can set query parameters', function () {
test('webhook message can set query parameters', function (): void {
$message = WebhookMessage::create()
->query(['param1' => 'value1', 'param2' => 'value2']);
expect($message->toArray()['query'])->toBe(['param1' => 'value1', 'param2' => 'value2']);
});
test('webhook message can set data', function () {
test('webhook message can set data', function (): void {
$data = ['key' => 'value', 'nested' => ['array' => 'data']];
$message = WebhookMessage::create()
->data($data);
@ -31,7 +31,7 @@ test('webhook message can set data', function () {
expect($message->toArray()['data'])->toBe($data);
});
test('webhook message can add headers', function () {
test('webhook message can add headers', function (): void {
$message = WebhookMessage::create()
->header('X-Custom-Header', 'custom-value')
->header('Authorization', 'Bearer token');
@ -41,7 +41,7 @@ test('webhook message can add headers', function () {
expect($headers['Authorization'])->toBe('Bearer token');
});
test('webhook message can set user agent', function () {
test('webhook message can set user agent', function (): void {
$message = WebhookMessage::create()
->userAgent('Test App/1.0');
@ -49,20 +49,20 @@ test('webhook message can set user agent', function () {
expect($headers['User-Agent'])->toBe('Test App/1.0');
});
test('webhook message can set verify option', function () {
test('webhook message can set verify option', function (): void {
$message = WebhookMessage::create()
->verify(true);
expect($message->toArray()['verify'])->toBeTrue();
});
test('webhook message verify defaults to false', function () {
test('webhook message verify defaults to false', function (): void {
$message = WebhookMessage::create();
expect($message->toArray()['verify'])->toBeFalse();
});
test('webhook message can chain methods', function () {
test('webhook message can chain methods', function (): void {
$message = WebhookMessage::create(['initial' => 'data'])
->query(['param' => 'value'])
->data(['updated' => 'data'])
@ -79,7 +79,7 @@ test('webhook message can chain methods', function () {
expect($array['verify'])->toBeTrue();
});
test('webhook message toArray returns correct structure', function () {
test('webhook message toArray returns correct structure', function (): void {
$message = WebhookMessage::create(['test' => 'data']);
$array = $message->toArray();