Skip to content

Commit daf6f5a

Browse files
committed
Merge pull request php-vcr#97 from jamiehannaford/various-fixes
Various fixes
2 parents ffbf750 + 625b6eb commit daf6f5a

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

src/VCR/Request.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,13 @@ public function getUrl()
197197
*/
198198
public function getHost()
199199
{
200-
return parse_url($this->getUrl(), PHP_URL_HOST);
200+
$host = parse_url($this->getUrl(), PHP_URL_HOST);
201+
202+
if ($port = parse_url($this->getUrl(), PHP_URL_PORT)) {
203+
$host .= ':' . $port;
204+
}
205+
206+
return $host;
201207
}
202208

203209
/**

src/VCR/RequestMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static function matchHeaders(Request $first, Request $second)
7171
{
7272
$firstHeaders = $first->getHeaders();
7373
foreach ($second->getHeaders() as $key => $pattern) {
74-
if (!isset($firstHeaders[$key])
74+
if (!array_key_exists($key, $firstHeaders)
7575
|| $pattern !== $firstHeaders[$key]) {
7676
return false;
7777
}

tests/VCR/RequestMatcherTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public function testMatchingHeaders()
5656
$this->assertFalse(RequestMatcher::matchHeaders($first, $second));
5757
}
5858

59+
public function testHeaderMatchingAllowsEmptyVals()
60+
{
61+
$first = new Request('GET', 'http://example.com', array('Accept' => null, 'Content-Type' => 'application/json'));
62+
$second = new Request('GET', 'http://example.com', array('Accept' => null, 'Content-Type' => 'application/json'));
63+
64+
$this->assertTrue(RequestMatcher::matchHeaders($first, $second));
65+
}
66+
5967
public function testMatchingPostFields()
6068
{
6169
$mock = array(

tests/VCR/RequestTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,10 @@ public function testDoesntMatchBody()
210210
)
211211
);
212212
}
213+
214+
public function testGetHostReturnsBothHostAndPort()
215+
{
216+
$request = new Request('GET', 'http://example.com:5000/foo?param=key');
217+
$this->assertEquals('example.com:5000', $request->getHost());
218+
}
213219
}

0 commit comments

Comments
 (0)