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

@ -6,7 +6,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
test('device log belongs to a device', function () {
test('device log belongs to a device', function (): void {
$device = Device::factory()->create();
$log = DeviceLog::factory()->create(['device_id' => $device->id]);
@ -14,7 +14,7 @@ test('device log belongs to a device', function () {
->and($log->device->id)->toBe($device->id);
});
test('device log casts log_entry to array', function () {
test('device log casts log_entry to array', function (): void {
Device::factory()->create();
$log = DeviceLog::factory()->create([
'log_entry' => [
@ -29,7 +29,7 @@ test('device log casts log_entry to array', function () {
->and($log->log_entry['level'])->toBe('info');
});
test('device log casts device_timestamp to datetime', function () {
test('device log casts device_timestamp to datetime', function (): void {
Device::factory()->create();
$timestamp = now();
$log = DeviceLog::factory()->create([
@ -40,7 +40,7 @@ test('device log casts device_timestamp to datetime', function () {
->and($log->device_timestamp->timestamp)->toBe($timestamp->timestamp);
});
test('device log factory creates valid data', function () {
test('device log factory creates valid data', function (): void {
Device::factory()->create();
$log = DeviceLog::factory()->create();
@ -50,7 +50,7 @@ test('device log factory creates valid data', function () {
->and($log->log_entry)->toHaveKeys(['creation_timestamp', 'device_status_stamp', 'log_id', 'log_message', 'log_codeline', 'log_sourcefile', 'additional_info']);
});
test('device log can be created with minimal required fields', function () {
test('device log can be created with minimal required fields', function (): void {
$device = Device::factory()->create();
$log = DeviceLog::create([
'device_id' => $device->id,

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
use App\Models\DeviceModel;
test('device model has required attributes', function () {
test('device model has required attributes', function (): void {
$deviceModel = DeviceModel::factory()->create([
'name' => 'Test Model',
'width' => 800,
@ -28,7 +28,7 @@ test('device model has required attributes', function () {
expect($deviceModel->offset_y)->toBe(0);
});
test('device model casts attributes correctly', function () {
test('device model casts attributes correctly', function (): void {
$deviceModel = DeviceModel::factory()->create([
'width' => '800',
'height' => '480',
@ -50,61 +50,61 @@ test('device model casts attributes correctly', function () {
expect($deviceModel->offset_y)->toBeInt();
});
test('get color depth attribute returns correct format for bit depth 2', function () {
test('get color depth attribute returns correct format for bit depth 2', function (): void {
$deviceModel = DeviceModel::factory()->create(['bit_depth' => 2]);
expect($deviceModel->getColorDepthAttribute())->toBe('2bit');
});
test('get color depth attribute returns correct format for bit depth 4', function () {
test('get color depth attribute returns correct format for bit depth 4', function (): void {
$deviceModel = DeviceModel::factory()->create(['bit_depth' => 4]);
expect($deviceModel->getColorDepthAttribute())->toBe('4bit');
});
test('get color depth attribute returns 4bit for bit depth greater than 4', function () {
test('get color depth attribute returns 4bit for bit depth greater than 4', function (): void {
$deviceModel = DeviceModel::factory()->create(['bit_depth' => 8]);
expect($deviceModel->getColorDepthAttribute())->toBe('4bit');
});
test('get color depth attribute returns null when bit depth is null', function () {
test('get color depth attribute returns null when bit depth is null', function (): void {
$deviceModel = new DeviceModel(['bit_depth' => null]);
expect($deviceModel->getColorDepthAttribute())->toBeNull();
});
test('get scale level attribute returns null for width 800 or less', function () {
test('get scale level attribute returns null for width 800 or less', function (): void {
$deviceModel = DeviceModel::factory()->create(['width' => 800]);
expect($deviceModel->getScaleLevelAttribute())->toBeNull();
});
test('get scale level attribute returns large for width between 801 and 1000', function () {
test('get scale level attribute returns large for width between 801 and 1000', function (): void {
$deviceModel = DeviceModel::factory()->create(['width' => 900]);
expect($deviceModel->getScaleLevelAttribute())->toBe('large');
});
test('get scale level attribute returns xlarge for width between 1001 and 1400', function () {
test('get scale level attribute returns xlarge for width between 1001 and 1400', function (): void {
$deviceModel = DeviceModel::factory()->create(['width' => 1200]);
expect($deviceModel->getScaleLevelAttribute())->toBe('xlarge');
});
test('get scale level attribute returns xxlarge for width greater than 1400', function () {
test('get scale level attribute returns xxlarge for width greater than 1400', function (): void {
$deviceModel = DeviceModel::factory()->create(['width' => 1500]);
expect($deviceModel->getScaleLevelAttribute())->toBe('xxlarge');
});
test('get scale level attribute returns null when width is null', function () {
test('get scale level attribute returns null when width is null', function (): void {
$deviceModel = new DeviceModel(['width' => null]);
expect($deviceModel->getScaleLevelAttribute())->toBeNull();
});
test('device model factory creates valid data', function () {
test('device model factory creates valid data', function (): void {
$deviceModel = DeviceModel::factory()->create();
expect($deviceModel->name)->not->toBeEmpty();

View file

@ -4,7 +4,7 @@ use App\Models\Playlist;
use App\Models\PlaylistItem;
use App\Models\Plugin;
test('playlist item belongs to playlist', function () {
test('playlist item belongs to playlist', function (): void {
$playlist = Playlist::factory()->create();
$playlistItem = PlaylistItem::factory()->create(['playlist_id' => $playlist->id]);
@ -13,7 +13,7 @@ test('playlist item belongs to playlist', function () {
->id->toBe($playlist->id);
});
test('playlist item belongs to plugin', function () {
test('playlist item belongs to plugin', function (): void {
$plugin = Plugin::factory()->create();
$playlistItem = PlaylistItem::factory()->create(['plugin_id' => $plugin->id]);
@ -22,7 +22,7 @@ test('playlist item belongs to plugin', function () {
->id->toBe($plugin->id);
});
test('playlist item can check if it is a mashup', function () {
test('playlist item can check if it is a mashup', function (): void {
$plugin = Plugin::factory()->create();
$regularItem = PlaylistItem::factory()->create([
'mashup' => null,
@ -44,7 +44,7 @@ test('playlist item can check if it is a mashup', function () {
->and($mashupItem->isMashup())->toBeTrue();
});
test('playlist item can get mashup name', function () {
test('playlist item can get mashup name', function (): void {
$plugin1 = Plugin::factory()->create();
$plugin2 = Plugin::factory()->create();
$mashupItem = PlaylistItem::factory()->create([
@ -59,7 +59,7 @@ test('playlist item can get mashup name', function () {
expect($mashupItem->getMashupName())->toBe('Test Mashup');
});
test('playlist item can get mashup layout type', function () {
test('playlist item can get mashup layout type', function (): void {
$plugin1 = Plugin::factory()->create();
$plugin2 = Plugin::factory()->create();
$mashupItem = PlaylistItem::factory()->create([
@ -74,7 +74,7 @@ test('playlist item can get mashup layout type', function () {
expect($mashupItem->getMashupLayoutType())->toBe('1Lx1R');
});
test('playlist item can get mashup plugin ids', function () {
test('playlist item can get mashup plugin ids', function (): void {
$plugin1 = Plugin::factory()->create();
$plugin2 = Plugin::factory()->create();
$mashupItem = PlaylistItem::factory()->create([
@ -89,7 +89,7 @@ test('playlist item can get mashup plugin ids', function () {
expect($mashupItem->getMashupPluginIds())->toBe([$plugin1->id, $plugin2->id]);
});
test('playlist item can get required plugin count for different layouts', function () {
test('playlist item can get required plugin count for different layouts', function (): void {
$layouts = [
'1Lx1R' => 2,
'1Tx1B' => 2,
@ -117,7 +117,7 @@ test('playlist item can get required plugin count for different layouts', functi
}
});
test('playlist item can get layout type', function () {
test('playlist item can get layout type', function (): void {
$layoutTypes = [
'1Lx1R' => 'vertical',
'1Lx2R' => 'vertical',
@ -144,7 +144,7 @@ test('playlist item can get layout type', function () {
}
});
test('playlist item can get layout size for different positions', function () {
test('playlist item can get layout size for different positions', function (): void {
$plugin1 = Plugin::factory()->create();
$plugin2 = Plugin::factory()->create();
$plugin3 = Plugin::factory()->create();
@ -163,7 +163,7 @@ test('playlist item can get layout size for different positions', function () {
->and($mashupItem->getLayoutSize(2))->toBe('half_vertical');
});
test('playlist item can get available layouts', function () {
test('playlist item can get available layouts', function (): void {
$layouts = PlaylistItem::getAvailableLayouts();
expect($layouts)->toBeArray()
@ -171,7 +171,7 @@ test('playlist item can get available layouts', function () {
->and($layouts['1Lx1R'])->toBe('1 Left - 1 Right (2 plugins)');
});
test('playlist item can get required plugin count for layout', function () {
test('playlist item can get required plugin count for layout', function (): void {
$layouts = [
'1Lx1R' => 2,
'1Tx1B' => 2,
@ -187,7 +187,7 @@ test('playlist item can get required plugin count for layout', function () {
}
});
test('playlist item can create mashup', function () {
test('playlist item can create mashup', function (): void {
$playlist = Playlist::factory()->create();
$plugins = Plugin::factory()->count(3)->create();
$pluginIds = $plugins->pluck('id')->toArray();

View file

@ -4,7 +4,7 @@ use App\Models\Device;
use App\Models\Playlist;
use App\Models\PlaylistItem;
test('playlist has required attributes', function () {
test('playlist has required attributes', function (): void {
$playlist = Playlist::factory()->create([
'name' => 'Test Playlist',
'is_active' => true,
@ -21,7 +21,7 @@ test('playlist has required attributes', function () {
->active_until->format('H:i')->toBe('17:00');
});
test('playlist belongs to device', function () {
test('playlist belongs to device', function (): void {
$device = Device::factory()->create();
$playlist = Playlist::factory()->create(['device_id' => $device->id]);
@ -30,7 +30,7 @@ test('playlist belongs to device', function () {
->id->toBe($device->id);
});
test('playlist has many items', function () {
test('playlist has many items', function (): void {
$playlist = Playlist::factory()->create();
$items = PlaylistItem::factory()->count(3)->create(['playlist_id' => $playlist->id]);
@ -39,7 +39,7 @@ test('playlist has many items', function () {
->each->toBeInstanceOf(PlaylistItem::class);
});
test('getNextPlaylistItem returns null when playlist is inactive', function () {
test('getNextPlaylistItem returns null when playlist is inactive', function (): void {
$playlist = Playlist::factory()->create(['is_active' => false]);
expect($playlist->getNextPlaylistItem())->toBeNull();

View file

@ -5,7 +5,7 @@ use Illuminate\Support\Facades\Http;
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
test('plugin has required attributes', function () {
test('plugin has required attributes', function (): void {
$plugin = Plugin::factory()->create([
'name' => 'Test Plugin',
'data_payload' => ['key' => 'value'],
@ -18,7 +18,7 @@ test('plugin has required attributes', function () {
->uuid->toMatch('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/');
});
test('plugin automatically generates uuid on creation', function () {
test('plugin automatically generates uuid on creation', function (): void {
$plugin = Plugin::factory()->create();
expect($plugin->uuid)
@ -26,14 +26,14 @@ test('plugin automatically generates uuid on creation', function () {
->toMatch('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/');
});
test('plugin can have custom uuid', function () {
test('plugin can have custom uuid', function (): void {
$uuid = Illuminate\Support\Str::uuid();
$plugin = Plugin::factory()->create(['uuid' => $uuid]);
expect($plugin->uuid)->toBe($uuid);
});
test('plugin data_payload is cast to array', function () {
test('plugin data_payload is cast to array', function (): void {
$data = ['key' => 'value'];
$plugin = Plugin::factory()->create(['data_payload' => $data]);
@ -42,7 +42,7 @@ test('plugin data_payload is cast to array', function () {
->toBe($data);
});
test('plugin can have polling body for POST requests', function () {
test('plugin can have polling body for POST requests', function (): void {
$plugin = Plugin::factory()->create([
'polling_verb' => 'post',
'polling_body' => '{"query": "query { user { id name } }"}',
@ -51,7 +51,7 @@ test('plugin can have polling body for POST requests', function () {
expect($plugin->polling_body)->toBe('{"query": "query { user { id name } }"}');
});
test('updateDataPayload sends POST request with body when polling_verb is post', function () {
test('updateDataPayload sends POST request with body when polling_verb is post', function (): void {
Http::fake([
'https://example.com/api' => Http::response(['success' => true], 200),
]);
@ -65,14 +65,12 @@ test('updateDataPayload sends POST request with body when polling_verb is post',
$plugin->updateDataPayload();
Http::assertSent(function ($request) {
return $request->url() === 'https://example.com/api' &&
$request->method() === 'POST' &&
$request->body() === '{"query": "query { user { id name } }"}';
});
Http::assertSent(fn ($request): bool => $request->url() === 'https://example.com/api' &&
$request->method() === 'POST' &&
$request->body() === '{"query": "query { user { id name } }"}');
});
test('updateDataPayload handles multiple URLs with IDX_ prefixes', function () {
test('updateDataPayload handles multiple URLs with IDX_ prefixes', function (): void {
$plugin = Plugin::factory()->create([
'data_strategy' => 'polling',
'polling_url' => "https://api1.example.com/data\nhttps://api2.example.com/weather\nhttps://api3.example.com/news",
@ -99,7 +97,7 @@ test('updateDataPayload handles multiple URLs with IDX_ prefixes', function () {
expect($plugin->data_payload['IDX_2'])->toBe(['headline' => 'test']);
});
test('updateDataPayload handles single URL without nesting', function () {
test('updateDataPayload handles single URL without nesting', function (): void {
$plugin = Plugin::factory()->create([
'data_strategy' => 'polling',
'polling_url' => 'https://api.example.com/data',
@ -120,7 +118,7 @@ test('updateDataPayload handles single URL without nesting', function () {
expect($plugin->data_payload)->not->toHaveKey('IDX_0');
});
test('updateDataPayload resolves Liquid variables in polling_header', function () {
test('updateDataPayload resolves Liquid variables in polling_header', function (): void {
$plugin = Plugin::factory()->create([
'data_strategy' => 'polling',
'polling_url' => 'https://api.example.com/data',
@ -139,15 +137,13 @@ test('updateDataPayload resolves Liquid variables in polling_header', function (
$plugin->updateDataPayload();
Http::assertSent(function ($request) {
return $request->url() === 'https://api.example.com/data' &&
$request->method() === 'GET' &&
$request->header('Authorization')[0] === 'Bearer test123' &&
$request->header('X-Custom-Header')[0] === 'custom_header_value';
});
Http::assertSent(fn ($request): bool => $request->url() === 'https://api.example.com/data' &&
$request->method() === 'GET' &&
$request->header('Authorization')[0] === 'Bearer test123' &&
$request->header('X-Custom-Header')[0] === 'custom_header_value');
});
test('updateDataPayload resolves Liquid variables in polling_body', function () {
test('updateDataPayload resolves Liquid variables in polling_body', function (): void {
$plugin = Plugin::factory()->create([
'data_strategy' => 'polling',
'polling_url' => 'https://api.example.com/data',
@ -166,7 +162,7 @@ test('updateDataPayload resolves Liquid variables in polling_body', function ()
$plugin->updateDataPayload();
Http::assertSent(function ($request) {
Http::assertSent(function ($request): bool {
$expectedBody = '{"query": "query { user { id name } }", "api_key": "test123", "user_id": "456"}';
return $request->url() === 'https://api.example.com/data' &&
@ -175,7 +171,7 @@ test('updateDataPayload resolves Liquid variables in polling_body', function ()
});
});
test('webhook plugin is stale if webhook event occurred', function () {
test('webhook plugin is stale if webhook event occurred', function (): void {
$plugin = Plugin::factory()->create([
'data_strategy' => 'webhook',
'data_payload_updated_at' => now()->subMinutes(10),
@ -186,7 +182,7 @@ test('webhook plugin is stale if webhook event occurred', function () {
});
test('webhook plugin data not stale if no webhook event occurred for 1 hour', function () {
test('webhook plugin data not stale if no webhook event occurred for 1 hour', function (): void {
$plugin = Plugin::factory()->create([
'data_strategy' => 'webhook',
'data_payload_updated_at' => now()->subMinutes(60),
@ -197,7 +193,7 @@ test('webhook plugin data not stale if no webhook event occurred for 1 hour', fu
});
test('plugin configuration is cast to array', function () {
test('plugin configuration is cast to array', function (): void {
$config = ['timezone' => 'UTC', 'refresh_interval' => 30];
$plugin = Plugin::factory()->create(['configuration' => $config]);
@ -206,7 +202,7 @@ test('plugin configuration is cast to array', function () {
->toBe($config);
});
test('plugin can get configuration value by key', function () {
test('plugin can get configuration value by key', function (): void {
$config = ['timezone' => 'UTC', 'refresh_interval' => 30];
$plugin = Plugin::factory()->create(['configuration' => $config]);
@ -215,7 +211,7 @@ test('plugin can get configuration value by key', function () {
expect($plugin->getConfiguration('nonexistent', 'default'))->toBe('default');
});
test('plugin configuration template is cast to array', function () {
test('plugin configuration template is cast to array', function (): void {
$template = [
'custom_fields' => [
[
@ -233,7 +229,7 @@ test('plugin configuration template is cast to array', function () {
->toBe($template);
});
test('resolveLiquidVariables resolves variables from configuration', function () {
test('resolveLiquidVariables resolves variables from configuration', function (): void {
$plugin = Plugin::factory()->create([
'configuration' => [
'api_key' => '12345',
@ -263,7 +259,7 @@ test('resolveLiquidVariables resolves variables from configuration', function ()
expect($result)->toBe('High');
});
test('resolveLiquidVariables handles invalid Liquid syntax gracefully', function () {
test('resolveLiquidVariables handles invalid Liquid syntax gracefully', function (): void {
$plugin = Plugin::factory()->create([
'configuration' => [
'api_key' => '12345',
@ -277,7 +273,7 @@ test('resolveLiquidVariables handles invalid Liquid syntax gracefully', function
->toThrow(Keepsuit\Liquid\Exceptions\SyntaxException::class);
});
test('plugin can extract default values from custom fields configuration template', function () {
test('plugin can extract default values from custom fields configuration template', function (): void {
$configurationTemplate = [
'custom_fields' => [
[
@ -323,7 +319,7 @@ test('plugin can extract default values from custom fields configuration templat
expect($plugin->getConfiguration('timezone'))->toBeNull();
});
test('resolveLiquidVariables resolves configuration variables correctly', function () {
test('resolveLiquidVariables resolves configuration variables correctly', function (): void {
$plugin = Plugin::factory()->create([
'configuration' => [
'Latitude' => '48.2083',
@ -338,7 +334,7 @@ test('resolveLiquidVariables resolves configuration variables correctly', functi
expect($plugin->resolveLiquidVariables($template))->toBe($expected);
});
test('resolveLiquidVariables handles missing variables gracefully', function () {
test('resolveLiquidVariables handles missing variables gracefully', function (): void {
$plugin = Plugin::factory()->create([
'configuration' => [
'Latitude' => '48.2083',
@ -351,7 +347,7 @@ test('resolveLiquidVariables handles missing variables gracefully', function ()
expect($plugin->resolveLiquidVariables($template))->toBe($expected);
});
test('resolveLiquidVariables handles empty configuration', function () {
test('resolveLiquidVariables handles empty configuration', function (): void {
$plugin = Plugin::factory()->create([
'configuration' => [],
]);