Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from troydavisson/matcher-fix
Fix for request matcher missing query string differences
- Loading branch information
Showing
4 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
namespace VCR; | ||
|
||
class RequestMatcherTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testMatchingMethod() | ||
{ | ||
$first = new Request('GET', 'http://example.com', array()); | ||
$second = new Request('GET', 'http://example.com', array()); | ||
|
||
$this->assertTrue(RequestMatcher::matchMethod($first, $second)); | ||
|
||
$first = new Request('GET', 'http://example.com', array()); | ||
$second = new Request('POST', 'http://example.com', array()); | ||
|
||
$this->assertFalse(RequestMatcher::matchMethod($first, $second)); | ||
} | ||
|
||
public function testMatchingUrl() | ||
{ | ||
$first = new Request('GET', 'http://example.com/common/path', array()); | ||
$second = new Request('GET', 'http://example.com/common/path', array()); | ||
|
||
$this->assertTrue(RequestMatcher::matchUrl($first, $second)); | ||
|
||
$first = new Request('GET', 'http://example.com/first/path', array()); | ||
$second = new Request('GET', 'http://example.com/second/path', array()); | ||
|
||
$this->assertFalse(RequestMatcher::matchUrl($first, $second)); | ||
} | ||
|
||
public function testMatchingHost() | ||
{ | ||
$first = new Request('GET', 'http://example.com/common/path', array()); | ||
$second = new Request('GET', 'http://example.com/common/path', array()); | ||
|
||
$this->assertTrue(RequestMatcher::matchHost($first, $second)); | ||
|
||
$first = new Request('GET', 'http://example.com/first/path', array()); | ||
$second = new Request('GET', 'http://elpmaxe.com/second/path', array()); | ||
|
||
$this->assertFalse(RequestMatcher::matchHost($first, $second)); | ||
} | ||
|
||
public function testMatchingHeaders() | ||
{ | ||
$first = new Request('GET', 'http://example.com', array( | ||
'Accept' => 'Everything', | ||
)); | ||
$second = new Request('GET', 'http://example.com', array( | ||
'Accept' => 'Everything', | ||
)); | ||
|
||
$this->assertTrue(RequestMatcher::matchHeaders($first, $second)); | ||
|
||
$first = new Request('GET', 'http://example.com', array( | ||
'Accept' => 'Everything', | ||
)); | ||
$second = new Request('GET', 'http://example.com', array( | ||
'Accept' => 'Nothing', | ||
)); | ||
|
||
$this->assertFalse(RequestMatcher::matchHeaders($first, $second)); | ||
} | ||
|
||
public function testMatchingPostFields() | ||
{ | ||
$mock = array( | ||
'method' => 'POST', | ||
'url' => 'http://example.com', | ||
'headers' => array(), | ||
'post_fields' => array( | ||
'field1' => 'value1', | ||
'field2' => 'value2', | ||
) | ||
); | ||
|
||
$first = Request::fromArray($mock); | ||
$second = Request::fromArray($mock); | ||
|
||
$this->assertTrue(RequestMatcher::matchPostFields($first, $second)); | ||
|
||
$mock['post_fields']['field2'] = 'changedvalue2'; | ||
$third = Request::fromArray($mock); | ||
|
||
$this->assertFalse(RequestMatcher::matchPostFields($first, $third)); | ||
} | ||
|
||
public function testMatchingQueryString() | ||
{ | ||
$first = new Request('GET', 'http://example.com/search?query=test', array()); | ||
$second = new Request('GET', 'http://example.com/search?query=test', array()); | ||
|
||
$this->assertTrue(RequestMatcher::matchQueryString($first, $second)); | ||
|
||
$first = new Request('GET', 'http://example.com/search?query=first', array()); | ||
$second = new Request('GET', 'http://example.com/search?query=second', array()); | ||
|
||
$this->assertFalse(RequestMatcher::matchQueryString($first, $second)); | ||
} | ||
} |