Skip to content

Commit 0eb5065

Browse files
chore: Ensure new options values are always set correctly
1 parent 90fcccf commit 0eb5065

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/Options.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,11 @@ public function __construct(array $options = [])
182182
$method = 'set' . $this->toPascalCase($option);
183183
if (method_exists($this, $method)) {
184184
// We want to make sure that we can set the individual arguments from an associative array or a regular array.
185-
$args = is_array($value) ? $value : [$value];
186-
$this->{$method}(...$args);
185+
if (is_array($value)) {
186+
$this->{$method}(...$value);
187+
} else {
188+
$this->{$method}($value);
189+
}
187190
}
188191
}
189192
}

tests/Unit/OptionsTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@
1818
'height' => 400,
1919
'fit' => 'fill',
2020
'watermarkPosition' => 'center',
21+
'border' => [
22+
'width' => 10,
23+
'color' => '000000',
24+
'borderMethod' => 'overlay',
25+
],
2126
]);
2227

2328
expect($options)->toBeOptions();
24-
expect($options->toString())->toBe('w=300&h=400&fit=fill&markpos=center');
29+
expect($options->toString())->toBe('w=300&h=400&fit=fill&markpos=center&border=10,000000,overlay');
2530
});
2631

2732
test('can handle complex options', function (): void {
@@ -31,10 +36,11 @@
3136
->setWatermarkPosition('center')
3237
->setWatermarkAlpha(50)
3338
->setQuality(80)
34-
->setFormat('png');
39+
->setFormat('png')
40+
->setBorder(10, '000000', 'overlay');
3541

3642
expect($options)->toBeOptions();
37-
expect($options->toString())->toBe('sharp=5&fit=fill&markpos=center&markalpha=50&q=80&fm=png');
43+
expect($options->toString())->toBe('sharp=5&fit=fill&markpos=center&markalpha=50&q=80&fm=png&border=10,000000,overlay');
3844
});
3945

4046
test('magic __toString behaves like toString method', function (): void {

0 commit comments

Comments
 (0)