Skip to content

Commit 7025568

Browse files
committed
feat: adds setCustomOption method
1 parent 3db0127 commit 7025568

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/Providers/Models/DTO/ModelConfig.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ public function getTools(): ?array
437437
return $this->tools;
438438
}
439439

440+
public function setCustomOption(string $key, mixed $value): void
441+
{
442+
$this->customOptions[$key] = $value;
443+
}
444+
440445
/**
441446
* Sets the custom options.
442447
*

tests/unit/Providers/Models/DTO/ModelConfigTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,4 +481,52 @@ public function testImplementsCorrectInterfaces(): void
481481
$config
482482
);
483483
}
484+
485+
/**
486+
* Tests setCustomOption method.
487+
*
488+
* @return void
489+
*/
490+
public function testSetCustomOption(): void
491+
{
492+
$config = new ModelConfig();
493+
494+
// Test setting a single custom option
495+
$config->setCustomOption('key1', 'value1');
496+
$customOptions = $config->getCustomOptions();
497+
$this->assertArrayHasKey('key1', $customOptions);
498+
$this->assertEquals('value1', $customOptions['key1']);
499+
500+
// Test setting multiple custom options
501+
$config->setCustomOption('key2', 42);
502+
$config->setCustomOption('key3', true);
503+
$config->setCustomOption('key4', ['nested' => 'array']);
504+
505+
$customOptions = $config->getCustomOptions();
506+
$this->assertCount(4, $customOptions);
507+
$this->assertEquals('value1', $customOptions['key1']);
508+
$this->assertEquals(42, $customOptions['key2']);
509+
$this->assertTrue($customOptions['key3']);
510+
$this->assertEquals(['nested' => 'array'], $customOptions['key4']);
511+
512+
// Test overwriting an existing custom option
513+
$config->setCustomOption('key1', 'new value');
514+
$customOptions = $config->getCustomOptions();
515+
$this->assertEquals('new value', $customOptions['key1']);
516+
517+
// Test that setCustomOption works with null values
518+
$config->setCustomOption('nullKey', null);
519+
$customOptions = $config->getCustomOptions();
520+
$this->assertArrayHasKey('nullKey', $customOptions);
521+
$this->assertNull($customOptions['nullKey']);
522+
523+
// Test that custom options are preserved in array conversion
524+
$array = $config->toArray();
525+
$this->assertArrayHasKey(ModelConfig::KEY_CUSTOM_OPTIONS, $array);
526+
$this->assertEquals($customOptions, $array[ModelConfig::KEY_CUSTOM_OPTIONS]);
527+
528+
// Test round-trip with custom options set via setCustomOption
529+
$restored = ModelConfig::fromArray($array);
530+
$this->assertEquals($customOptions, $restored->getCustomOptions());
531+
}
484532
}

0 commit comments

Comments
 (0)