feat: Update ApplicationSetting model to include additional boolean casts

- Changed `$cast` to `$casts` in ApplicationSetting model to enable proper boolean casting for new fields.
- Added boolean fields: `is_spa`, `is_build_server_enabled`, `is_preserve_repository_enabled`, `is_container_label_escape_enabled`, `is_container_label_readonly_enabled`, and `use_build_secrets`.

fix: Update Livewire component to reflect new property names

- Updated references in the Livewire component for the new camelCase property names.
- Adjusted bindings and IDs for consistency with the updated model.

test: Add unit tests for ApplicationSetting boolean casting

- Created tests to verify boolean casting for `is_static` and other boolean fields in ApplicationSetting.
- Ensured all boolean fields are correctly defined in the casts array.

test: Implement tests for SynchronizesModelData trait

- Added tests to verify the functionality of the SynchronizesModelData trait, ensuring it correctly syncs properties between the component and the model.
- Included tests for handling non-existent properties gracefully.
This commit is contained in:
Andras Bacsai committed 2025-11-04 08:43:33 +01:00
1 parent d291d85311
commit fbaa5eb369
5 files changed
+615 -288

No files matched your search

@@ -0,0 +1,105 @@
<?php
/**
* Tests for ApplicationSetting model boolean casting
*
* NOTE: These tests verify that the is_static field properly casts to boolean.
* The fix changes $cast to $casts to enable proper Laravel boolean casting.
*/
use App\Models\ApplicationSetting;
it('casts is_static to boolean when true', function () {
$setting = new ApplicationSetting;
$setting->is_static = true;
// Verify it's cast to boolean
expect($setting->is_static)->toBeTrue()
->and($setting->is_static)->toBeBool();
});
it('casts is_static to boolean when false', function () {
$setting = new ApplicationSetting;
$setting->is_static = false;
// Verify it's cast to boolean
expect($setting->is_static)->toBeFalse()
->and($setting->is_static)->toBeBool();
});
it('casts is_static from string "1" to boolean true', function () {
$setting = new ApplicationSetting;
$setting->is_static = '1';
// Should cast string to boolean
expect($setting->is_static)->toBeTrue()
->and($setting->is_static)->toBeBool();
});
it('casts is_static from string "0" to boolean false', function () {
$setting = new ApplicationSetting;
$setting->is_static = '0';
// Should cast string to boolean
expect($setting->is_static)->toBeFalse()
->and($setting->is_static)->toBeBool();
});
it('casts is_static from integer 1 to boolean true', function () {
$setting = new ApplicationSetting;
$setting->is_static = 1;
// Should cast integer to boolean
expect($setting->is_static)->toBeTrue()
->and($setting->is_static)->toBeBool();
});
it('casts is_static from integer 0 to boolean false', function () {
$setting = new ApplicationSetting;
$setting->is_static = 0;
// Should cast integer to boolean
expect($setting->is_static)->toBeFalse()
->and($setting->is_static)->toBeBool();
});
it('has casts array property defined correctly', function () {
$setting = new ApplicationSetting;
// Verify the casts property exists and is configured
$casts = $setting->getCasts();
expect($casts)->toHaveKey('is_static')
->and($casts['is_static'])->toBe('boolean');
});
it('casts all boolean fields correctly', function () {
$setting = new ApplicationSetting;
// Get all casts
$casts = $setting->getCasts();
// Verify all expected boolean fields are cast
$expectedBooleanCasts = [
'is_static',
'is_spa',
'is_build_server_enabled',
'is_preserve_repository_enabled',
'is_container_label_escape_enabled',
'is_container_label_readonly_enabled',
'use_build_secrets',
'is_auto_deploy_enabled',
'is_force_https_enabled',
'is_debug_enabled',
'is_preview_deployments_enabled',
'is_pr_deployments_public_enabled',
'is_git_submodules_enabled',
'is_git_lfs_enabled',
'is_git_shallow_clone_enabled',
];
foreach ($expectedBooleanCasts as $field) {
expect($casts)->toHaveKey($field)
->and($casts[$field])->toBe('boolean');
}
});
+163
View File
@@ -0,0 +1,163 @@
<?php
/**
* Tests for SynchronizesModelData trait
*
* NOTE: These tests verify that the trait properly handles nested Eloquent models
* and marks them as dirty when syncing properties.
*/
use App\Livewire\Concerns\SynchronizesModelData;
use App\Models\Application;
use App\Models\ApplicationSetting;
it('syncs nested eloquent model properties correctly', function () {
// Create a test component that uses the trait
$component = new class
{
use SynchronizesModelData;
public bool $is_static = true;
public Application $application;
protected function getModelBindings(): array
{
return [
'is_static' => 'application.settings.is_static',
];
}
// Expose protected method for testing
public function testSync(): void
{
$this->syncToModel();
}
};
// Create real ApplicationSetting instance
$settings = new ApplicationSetting;
$settings->is_static = false;
// Create Application instance
$application = new Application;
$application->setRelation('settings', $settings);
$component->application = $application;
$component->is_static = true;
// Sync to model
$component->testSync();
// Verify the value was set on the model
expect($component->application->settings->is_static)->toBeTrue();
});
it('syncs boolean values correctly', function () {
$component = new class
{
use SynchronizesModelData;
public bool $is_spa = true;
public bool $is_build_server_enabled = false;
public Application $application;
protected function getModelBindings(): array
{
return [
'is_spa' => 'application.settings.is_spa',
'is_build_server_enabled' => 'application.settings.is_build_server_enabled',
];
}
public function testSync(): void
{
$this->syncToModel();
}
};
$settings = new ApplicationSetting;
$settings->is_spa = false;
$settings->is_build_server_enabled = true;
$application = new Application;
$application->setRelation('settings', $settings);
$component->application = $application;
$component->testSync();
expect($component->application->settings->is_spa)->toBeTrue()
->and($component->application->settings->is_build_server_enabled)->toBeFalse();
});
it('syncs from model to component correctly', function () {
$component = new class
{
use SynchronizesModelData;
public bool $is_static = false;
public bool $is_spa = false;
public Application $application;
protected function getModelBindings(): array
{
return [
'is_static' => 'application.settings.is_static',
'is_spa' => 'application.settings.is_spa',
];
}
public function testSyncFrom(): void
{
$this->syncFromModel();
}
};
$settings = new ApplicationSetting;
$settings->is_static = true;
$settings->is_spa = true;
$application = new Application;
$application->setRelation('settings', $settings);
$component->application = $application;
$component->testSyncFrom();
expect($component->is_static)->toBeTrue()
->and($component->is_spa)->toBeTrue();
});
it('handles properties that do not exist gracefully', function () {
$component = new class
{
use SynchronizesModelData;
public Application $application;
protected function getModelBindings(): array
{
return [
'non_existent_property' => 'application.name',
];
}
public function testSync(): void
{
$this->syncToModel();
}
};
$application = new Application;
$component->application = $application;
// Should not throw an error
$component->testSync();
expect(true)->toBeTrue();
});