refactor: Improve handling of custom network aliases

The custom_network_aliases attribute in the Application model was being cast to an array directly. This commit refactors the attribute to provide both a string representation (for compatibility with older configurations and hashing) and an array representation for internal use. This ensures that network aliases are correctly parsed and utilized, preventing potential issues during deployment and configuration updates.
This commit is contained in:
Andras Bacsai
2025-11-01 13:13:14 +01:00
parent c34e5c803b
commit 9a664865ee
5 changed files with 142 additions and 4 deletions

View File

@@ -0,0 +1,50 @@
<?php
use App\Models\Application;
/**
* Unit test to verify custom_network_aliases conversion from array to string.
*
* The issue: Application model's accessor returns an array, but the Livewire
* component property is typed as ?string for the text input field.
* The conversion happens in mount() after syncFromModel().
*/
it('converts array aliases to comma-separated string', function () {
// Test that an array is correctly converted to a string
$aliases = ['api.internal', 'api.local'];
$result = implode(',', $aliases);
expect($result)->toBe('api.internal,api.local')
->and($result)->toBeString();
});
it('handles null aliases', function () {
// Test that null remains null
$aliases = null;
if (is_array($aliases)) {
$result = implode(',', $aliases);
} else {
$result = $aliases;
}
expect($result)->toBeNull();
});
it('handles empty array aliases', function () {
// Test that empty array becomes empty string
$aliases = [];
$result = implode(',', $aliases);
expect($result)->toBe('')
->and($result)->toBeString();
});
it('handles single alias', function () {
// Test that single-element array is converted correctly
$aliases = ['api.internal'];
$result = implode(',', $aliases);
expect($result)->toBe('api.internal')
->and($result)->toBeString();
});