Skip to content

Commit

Permalink
Merge pull request #12 from peterjaap/patch-1
Browse files Browse the repository at this point in the history
Allow setting custom options
  • Loading branch information
crocodile2u committed Nov 27, 2023
2 parents 6575855 + c92a727 commit 7d267ca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/OptionSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ private function set(string $name, ...$args): self
return $this;
}

public function setUnsafe(string $name, ...$args): self
{
return $this->set($name, ...$args);
}

public function unset(string $name): self
{
unset($this->options[$name]);
Expand Down
18 changes: 18 additions & 0 deletions test/OptionSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Imgproxy\UnsharpeningMode;
use Imgproxy\WatermarkPosition;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

class OptionSetTest extends TestCase
{
Expand Down Expand Up @@ -973,6 +974,23 @@ public function testWithQuality()
$this->assertEquals(70, $os->quality());
}

public function testSetUnsafe(): void
{
$os = new OptionSet();
$optionName = 'zoom';
$args = ['2', '2'];

$os->setUnsafe($optionName, ...$args);

$reflectionClass = new ReflectionClass(OptionSet::class);
$optionsProperty = $reflectionClass->getProperty('options');
$optionsProperty->setAccessible(true);
$options = $optionsProperty->getValue($os);

$this->assertArrayHasKey($optionName, $options);
$this->assertSame($args, $options[$optionName]);
}

public function testUnset()
{
$os = new OptionSet();
Expand Down

0 comments on commit 7d267ca

Please sign in to comment.