Skip to content

Commit 3697b1f

Browse files
committed
Make MimeType::isType case-insensitive
Updated the isType method in MimeType to perform case-insensitive checks by converting the input to lowercase. Adjusted and expanded unit tests to verify case insensitivity and improved test coverage.
1 parent b599206 commit 3697b1f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/Files/ValueObjects/MimeType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public static function isValid(string $mimeType): bool
181181
*/
182182
public function isType(string $mimeType): bool
183183
{
184-
return strpos($this->value, $mimeType . '/') === 0;
184+
return strpos($this->value, strtolower($mimeType) . '/') === 0;
185185
}
186186

187187
/**

tests/unit/Files/ValueObjects/MimeTypeTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,21 @@ public function testNormalizesValues(): void
283283
$this->assertEquals('image/jpeg', (string) $mimeType);
284284
}
285285

286-
public function testHasMimeType(): void
286+
public function testIsType(): void
287287
{
288-
$mimeType = new MimeType('image/jpeg');
288+
$imageType = new MimeType('image/jpeg');
289289
$fontType = new MimeType('font/ttf');
290290

291-
$this->assertTrue($mimeType->isType('image'));
292-
$this->assertFalse($mimeType->isType('video'));
291+
$this->assertTrue($imageType->isType('image'));
292+
$this->assertFalse($imageType->isType('video'));
293293

294294
$this->assertTrue($fontType->isType('font'));
295295
$this->assertFalse($fontType->isType('image'));
296+
297+
// Case insensitive.
298+
$this->assertTrue($fontType->isType('Font'));
299+
$this->assertTrue($fontType->isType('FONT'));
300+
$this->assertTrue($imageType->isType('image'));
301+
$this->assertTrue($imageType->isType('IMAGE'));
296302
}
297303
}

0 commit comments

Comments
 (0)