Skip to content

Commit 7317b5c

Browse files
committed
Check that at least one format quality must be set.
1 parent 67a5c78 commit 7317b5c

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/Options/FormatQuality.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Onliner\ImgProxy\Options;
66

7+
use InvalidArgumentException;
8+
79
final class FormatQuality extends AbstractOption
810
{
911
/**
@@ -20,6 +22,10 @@ public function __construct(array $options)
2022
$data = (new Quality($quality))->data();
2123
$this->options[] = [$format, ...$data];
2224
}
25+
26+
if (empty($this->options)) {
27+
throw new InvalidArgumentException('At least one format quality must be set');
28+
}
2329
}
2430

2531
/**

tests/Options/FormatQualityTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,22 @@ public function testCreate(array $options, string $expected): void
2222
/**
2323
* @dataProvider invalidData
2424
*/
25-
public function testCreateFail(int $quality): void
25+
public function testCreateFailInvalidQuality(int $quality): void
2626
{
2727
$this->expectException(\InvalidArgumentException::class);
2828
$this->expectExceptionMessage("Invalid quality: $quality");
2929

3030
new FormatQuality(['png' => $quality]);
3131
}
3232

33+
public function testCreateFailEmptyOptions(): void
34+
{
35+
$this->expectException(\InvalidArgumentException::class);
36+
$this->expectExceptionMessage('At least one format quality must be set');
37+
38+
new FormatQuality([]);
39+
}
40+
3341
/**
3442
* @return array[]
3543
*/

0 commit comments

Comments
 (0)