Skip to content

Commit 5970b61

Browse files
author
Ben Ramsey
committed
Tests and full coverage for Mimeparse::parseMimeType
1 parent 75aafc1 commit 5970b61

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Bitworking/Mimeparse.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Mimeparse
2727
*
2828
* @param string $mimeType
2929
* @return array ($type, $subtype, $params)
30+
* @throws UnexpectedValueException when $mimeType does not include a valid subtype
3031
*/
3132
public static function parseMimeType($mimeType)
3233
{
@@ -51,7 +52,7 @@ public static function parseMimeType($mimeType)
5152
list($type, $subtype) = explode('/', $fullType);
5253

5354
if (!$subtype) {
54-
throw (new \Exception('malformed mime type'));
55+
throw new \UnexpectedValueException('malformed mime type');
5556
}
5657

5758
return array(trim($type), trim($subtype), $params);

tests/Bitworking/MimeparseTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class MimeparseTest extends \PHPUnit_Framework_TestCase
55
{
66
/**
77
* @covers Bitworking\Mimeparse::parseMediaRange
8+
* @covers Bitworking\Mimeparse::parseMimeType
89
*/
910
public function testParseMediaRange()
1011
{
@@ -35,6 +36,16 @@ public function testParseMediaRange()
3536
), Mimeparse::parseMediaRange(' *; q=.2'));
3637
}
3738

39+
/**
40+
* @covers Bitworking\Mimeparse::parseMimeType
41+
* @expectedException UnexpectedValueException
42+
* @expectedExceptionMessage malformed mime type
43+
*/
44+
public function testParseMimeTypeWithMalformedMimeType()
45+
{
46+
$parsed = Mimeparse::parseMimeType('application/;q=1');
47+
}
48+
3849
/**
3950
* @covers Bitworking\Mimeparse::quality
4051
*/

0 commit comments

Comments
 (0)