Skip to content

Commit 7c74da9

Browse files
author
Ben Ramsey
committed
Following the visibilty of the Java MIMEParse class
See Java version of MIMEParse at http://code.google.com/p/mimeparse/source/browse/trunk/java/MIMEParse.java This class sets certain methods as protected, something that Python doesn't concern itself with. I am following suit with the PHP version of the library and using the same visibility as the Java class.
1 parent 5970b61 commit 7c74da9

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

src/Bitworking/Mimeparse.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Mimeparse
2929
* @return array ($type, $subtype, $params)
3030
* @throws UnexpectedValueException when $mimeType does not include a valid subtype
3131
*/
32-
public static function parseMimeType($mimeType)
32+
protected static function parseMimeType($mimeType)
3333
{
3434
$parts = explode(';', $mimeType);
3535

@@ -76,7 +76,7 @@ public static function parseMimeType($mimeType)
7676
* @param string $range
7777
* @return array ($type, $subtype, $params)
7878
*/
79-
public static function parseMediaRange($range)
79+
protected static function parseMediaRange($range)
8080
{
8181
list($type, $subtype, $params) = self::parseMimeType($range);
8282

@@ -104,7 +104,7 @@ public static function parseMediaRange($range)
104104
* @param array $parsedRanges
105105
* @return array ($bestFitness, $bestFitQuality)
106106
*/
107-
public static function fitnessAndQualityParsed($mimeType, $parsedRanges)
107+
protected static function fitnessAndQualityParsed($mimeType, $parsedRanges)
108108
{
109109
$bestFitness = -1;
110110
$bestFitQuality = 0;
@@ -149,7 +149,7 @@ public static function fitnessAndQualityParsed($mimeType, $parsedRanges)
149149
* @param array $parsedRanges
150150
* @return float $q
151151
*/
152-
public static function qualityParsed($mimeType, $parsedRanges)
152+
protected static function qualityParsed($mimeType, $parsedRanges)
153153
{
154154
list($fitness, $q) = self::fitnessAndQualityParsed($mimeType, $parsedRanges);
155155
return $q;
@@ -212,5 +212,14 @@ public static function bestMatch($supported, $header)
212212
$a = $weightedMatches[count($weightedMatches) - 1];
213213
return (empty($a[0][1]) ? null : $a[1]);
214214
}
215+
216+
/**
217+
* Disable access to constructor
218+
*
219+
* @codeCoverageIgnore
220+
*/
221+
private function __construct()
222+
{
223+
}
215224
}
216225

tests/Bitworking/MimeparseTest.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,64 @@
44
class MimeparseTest extends \PHPUnit_Framework_TestCase
55
{
66
/**
7+
* Testing this protected method because it includes a lot of parsing
8+
* functionality that we wish to isolate from other tests.
9+
*
710
* @covers Bitworking\Mimeparse::parseMediaRange
811
* @covers Bitworking\Mimeparse::parseMimeType
912
*/
1013
public function testParseMediaRange()
1114
{
15+
$method = new \ReflectionMethod('Bitworking\Mimeparse', 'parseMediaRange');
16+
$method->setAccessible(true);
17+
1218
$expected1 = array(
1319
0 => 'application',
1420
1 => 'xml',
1521
2 => array('q' => '1'),
1622
);
1723

18-
$this->assertEquals($expected1, Mimeparse::parseMediaRange('application/xml;q=1'));
19-
$this->assertEquals($expected1, Mimeparse::parseMediaRange('application/xml'));
20-
$this->assertEquals($expected1, Mimeparse::parseMediaRange('application/xml;q='));
24+
$this->assertEquals($expected1, $method->invoke(null, 'application/xml;q=1'));
25+
$this->assertEquals($expected1, $method->invoke(null, 'application/xml'));
26+
$this->assertEquals($expected1, $method->invoke(null, 'application/xml;q='));
2127

2228
$expected2 = array(
2329
0 => 'application',
2430
1 => 'xml',
2531
2 => array('q' => '1', 'b' => 'other'),
2632
);
2733

28-
$this->assertEquals($expected2, Mimeparse::parseMediaRange('application/xml ; q=1;b=other'));
29-
$this->assertEquals($expected2, Mimeparse::parseMediaRange('application/xml ; q=2;b=other'));
34+
$this->assertEquals($expected2, $method->invoke(null, 'application/xml ; q=1;b=other'));
35+
$this->assertEquals($expected2, $method->invoke(null, 'application/xml ; q=2;b=other'));
3036

3137
// Java URLConnection class sends an Accept header that includes a single "*"
3238
$this->assertEquals(array(
3339
0 => '*',
3440
1 => '*',
3541
2 => array('q' => '.2'),
36-
), Mimeparse::parseMediaRange(' *; q=.2'));
42+
), $method->invoke(null, ' *; q=.2'));
3743
}
3844

3945
/**
46+
* Testing this protected method because it throws an exception that we
47+
* want to test.
48+
*
4049
* @covers Bitworking\Mimeparse::parseMimeType
4150
* @expectedException UnexpectedValueException
4251
* @expectedExceptionMessage malformed mime type
4352
*/
4453
public function testParseMimeTypeWithMalformedMimeType()
4554
{
46-
$parsed = Mimeparse::parseMimeType('application/;q=1');
55+
$method = new \ReflectionMethod('Bitworking\Mimeparse', 'parseMediaRange');
56+
$method->setAccessible(true);
57+
58+
$parsed = $method->invoke(null, 'application/;q=1');
4759
}
4860

4961
/**
5062
* @covers Bitworking\Mimeparse::quality
63+
* @covers Bitworking\Mimeparse::qualityParsed
64+
* @covers Bitworking\Mimeparse::fitnessAndQualityParsed
5165
*/
5266
public function testQuality()
5367
{

0 commit comments

Comments
 (0)