Skip to content

Commit

Permalink
Merge pull request #418 from deluxetom/3.x-missing-param
Browse files Browse the repository at this point in the history
Fixed param typo
  • Loading branch information
ADmad authored Dec 20, 2024
2 parents 142bd4e + 7b8fa08 commit d6539da
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
6 changes: 2 additions & 4 deletions src/Manipulators/BaseManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class BaseManipulator implements ManipulatorInterface
*/
public function setParams(array $params): static
{
$this->params = $params;
$this->params = array_filter($params, fn (string $key): bool => in_array($key, $this->getApiParams()), ARRAY_FILTER_USE_KEY);

return $this;
}
Expand All @@ -30,8 +30,6 @@ public function setParams(array $params): static
*/
public function getParam(string $name): mixed
{
return array_key_exists($name, $this->params)
? $this->params[$name]
: null;
return $this->params[$name] ?? null;
}
}
2 changes: 1 addition & 1 deletion src/Manipulators/Border.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Border extends BaseManipulator
{
public function getApiParams(): array
{
return ['border'];
return ['border', 'dpr'];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Manipulators/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(?int $maxImageSize = null)

public function getApiParams(): array
{
return ['w', 'f', 'fit', 'dpr'];
return ['w', 'h', 'fit', 'dpr'];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Manipulators/Watermark.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(?FilesystemOperator $watermarks = null, string $wate

public function getApiParams(): array
{
return ['mark', 'markw', 'markh', 'markx', 'marky', 'markpad', 'markfit', 'markpos', 'markalpha', 'dpr'];
return ['mark', 'markw', 'markh', 'markx', 'marky', 'markpad', 'markfit', 'markpos', 'markalpha', 'dpr', 'w', 'h'];
}

/**
Expand Down
18 changes: 9 additions & 9 deletions tests/Api/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class ApiTest extends TestCase
{
private $api;
private Api $api;

public function setUp(): void
{
Expand All @@ -24,38 +24,38 @@ public function tearDown(): void
\Mockery::close();
}

public function testCreateInstance()
public function testCreateInstance(): void
{
$this->assertInstanceOf(Api::class, $this->api);
}

public function testSetImageManager()
public function testSetImageManager(): void
{
$this->api->setImageManager(ImageManager::gd());
$this->assertInstanceOf(ImageManager::class, $this->api->getImageManager());
}

public function testGetImageManager()
public function testGetImageManager(): void
{
$this->assertInstanceOf(ImageManager::class, $this->api->getImageManager());
}

public function testSetManipulators()
public function testSetManipulators(): void
{
$this->api->setManipulators([\Mockery::mock(ManipulatorInterface::class)]);
$manipulators = $this->api->getManipulators();
$this->assertInstanceOf(ManipulatorInterface::class, $manipulators[0]);
}

public function testSetInvalidManipulator()
public function testSetInvalidManipulator(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Not a valid manipulator.');

$this->api->setManipulators([new \stdClass()]);
}

public function testGetManipulators()
public function testGetManipulators(): void
{
$this->assertEquals([], $this->api->getManipulators());
}
Expand All @@ -73,7 +73,7 @@ public function testGetApiParams(): void
$this->assertEquals(array_merge(Api::GLOBAL_API_PARAMS, ['foo', 'bar', 'baz']), $api->getApiParams());
}

public function testRun()
public function testRun(): void
{
$image = \Mockery::mock(ImageInterface::class, function ($mock) {
$mock->shouldReceive('origin')->andReturn(\Mockery::mock('\Intervention\Image\Origin', function ($mock) {
Expand All @@ -96,7 +96,7 @@ public function testRun()
$api = new Api($manager, [$manipulator]);

$this->assertEquals('encoded', $api->run(
file_get_contents(dirname(__FILE__, 2).'/files/red-pixel.png'),
(string) file_get_contents(dirname(__FILE__, 2).'/files/red-pixel.png'),
[]
));
}
Expand Down

0 comments on commit d6539da

Please sign in to comment.