Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed param typo #418

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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