Skip to content

Commit 4087b41

Browse files
authored
Merge pull request php-vcr#247 from moufmouf/fix_integration_tests
Fixing broken integration tests
2 parents a45aa4c + 9bad9fb commit 4087b41

File tree

3 files changed

+34
-59
lines changed

3 files changed

+34
-59
lines changed

tests/integration/guzzle/test/VCR/Example/ExampleHttpClientTest.php

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class ExampleHttpClientTest extends \PHPUnit_Framework_TestCase
1111
{
12-
const TEST_GET_URL = 'http://httpbin.org/get';
12+
const TEST_GET_URL = 'http://api.chew.pro/trbmb';
1313
const TEST_POST_URL = 'http://httpbin.org/post';
1414
const TEST_POST_BODY = '{"foo":"bar"}';
1515

@@ -26,54 +26,39 @@ public function setUp()
2626
\VCR\VCR::configure()->setCassettePath(vfsStream::url('testDir'));
2727
}
2828

29-
public function testRequestGETDirect()
29+
public function testRequestGET()
3030
{
31-
$this->assertValidGETResponse($this->requestGET());
32-
}
33-
34-
public function testRequestGETIntercepted()
35-
{
36-
$this->assertValidGETResponse($this->requestGETIntercepted());
37-
}
38-
39-
public function testRequestGETDirectEqualsIntercepted()
40-
{
41-
$this->assertEquals($this->requestGET(), $this->requestGETIntercepted());
42-
}
43-
44-
public function testRequestGETInterceptedIsRepeatable()
45-
{
46-
$this->assertEquals($this->requestGETIntercepted(), $this->requestGETIntercepted());
47-
}
48-
49-
public function testRequestPOSTDirect()
50-
{
51-
$this->assertValidPOSTResponse($this->requestPOST());
52-
}
53-
54-
public function testRequestPOSTIntercepted()
55-
{
56-
$this->assertValidPOSTResponse($this->requestPOSTIntercepted());
57-
}
58-
59-
public function testRequestPOSTDirectEqualsIntercepted()
60-
{
61-
$this->assertEquals($this->requestPOST(), $this->requestPOSTIntercepted());
31+
\VCR\VCR::turnOn();
32+
\VCR\VCR::insertCassette('test-cassette.yml');
33+
$originalRequest = $this->requestGET();
34+
$this->assertValidGETResponse($originalRequest);
35+
$interceptedRequest = $this->requestGET();
36+
$this->assertValidGETResponse($interceptedRequest);
37+
$this->assertEquals($originalRequest, $interceptedRequest);
38+
$repeatInterceptedRequest = $this->requestGET();
39+
$this->assertEquals($interceptedRequest, $repeatInterceptedRequest);
40+
\VCR\VCR::turnOff();
6241
}
6342

64-
public function testRequestPOSTInterceptedIsRepeatable()
43+
public function testRequestPOST()
6544
{
66-
$this->assertEquals($this->requestPOSTIntercepted(), $this->requestPOSTIntercepted());
45+
\VCR\VCR::turnOn();
46+
\VCR\VCR::insertCassette('test-cassette.yml');
47+
$originalRequest = $this->requestPOST();
48+
$this->assertValidPOSTResponse($originalRequest);
49+
$interceptedRequest = $this->requestPOST();
50+
$this->assertValidPOSTResponse($interceptedRequest);
51+
$this->assertEquals($originalRequest, $interceptedRequest);
52+
$repeatInterceptedRequest = $this->requestPOST();
53+
$this->assertEquals($interceptedRequest, $repeatInterceptedRequest);
54+
\VCR\VCR::turnOff();
6755
}
6856

6957
protected function requestGET()
7058
{
7159
$exampleClient = new ExampleHttpClient();
7260

7361
$response = $exampleClient->get(self::TEST_GET_URL);
74-
foreach ($this->ignoreHeaders as $header) {
75-
unset($response['headers'][$header]);
76-
}
7762

7863
return $response;
7964
}
@@ -86,20 +71,11 @@ protected function requestPOST()
8671
foreach ($this->ignoreHeaders as $header) {
8772
unset($response['headers'][$header]);
8873
}
74+
unset($response['origin']);
8975

9076
return $response;
9177
}
9278

93-
protected function requestGETIntercepted()
94-
{
95-
\VCR\VCR::turnOn();
96-
\VCR\VCR::insertCassette('test-cassette.yml');
97-
$info = $this->requestGET();
98-
\VCR\VCR::turnOff();
99-
100-
return $info;
101-
}
102-
10379
protected function requestPOSTIntercepted()
10480
{
10581
\VCR\VCR::turnOn();
@@ -113,10 +89,7 @@ protected function requestPOSTIntercepted()
11389
protected function assertValidGETResponse($info)
11490
{
11591
$this->assertInternalType('array', $info, 'Response is not an array.');
116-
$this->assertArrayHasKey('url', $info, "Key 'url' not found.");
117-
$this->assertEquals(self::TEST_GET_URL, $info['url'], "Value for key 'url' wrong.");
118-
$this->assertArrayHasKey('headers', $info, "Key 'headers' not found.");
119-
$this->assertInternalType('array', $info['headers'], 'Headers is not an array.');
92+
$this->assertArrayHasKey('0', $info, 'API did not return any value.');
12093
}
12194

12295
protected function assertValidPOSTResponse($info)

tests/integration/soap/src/VCR/Example/ExampleSoapClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
*/
1010
class ExampleSoapClient
1111
{
12-
const EXAMPLE_WSDL = 'http://www.webservicex.net/ConvertTemperature.asmx?WSDL';
12+
const EXAMPLE_WSDL = 'http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL';
1313

14-
public function call($zip = '10')
14+
public function call($number = 12)
1515
{
1616
$client = new \SoapClient(self::EXAMPLE_WSDL, array('soap_version' => SOAP_1_2));
17-
$response = $client->ConvertTemp(array('Temperature' => $zip, 'FromUnit' => 'degreeCelsius', 'ToUnit' => 'degreeFahrenheit'));
17+
$response = $client->NumberToWords(array('ubiNum' => $number));
1818

19-
return (int) $response->ConvertTempResult;
19+
return trim((string) $response->NumberToWordsResult);
2020
}
2121
}

tests/integration/soap/test/VCR/Example/ExampleSoapClientTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ public function setUp()
2121
public function testCallDirectly()
2222
{
2323
$actual = $this->callSoap();
24-
$this->assertInternalType('integer', $actual);
24+
$this->assertInternalType('string', $actual);
25+
$this->assertEquals('twelve', $actual);
2526
}
2627

2728
public function testCallIntercepted()
2829
{
2930
$actual = $this->callSoapIntercepted();
30-
$this->assertInternalType('integer', $actual);
31+
$this->assertInternalType('string', $actual);
32+
$this->assertEquals('twelve', $actual);
3133
}
3234

3335
public function testCallDirectlyEqualsIntercepted()
@@ -38,7 +40,7 @@ public function testCallDirectlyEqualsIntercepted()
3840
protected function callSoap()
3941
{
4042
$soapClient = new ExampleSoapClient();
41-
return $soapClient->call('10013'); // somewhere in New York
43+
return $soapClient->call(12);
4244
}
4345

4446
protected function callSoapIntercepted()

0 commit comments

Comments
 (0)