Skip to content

Commit dc33b5c

Browse files
committed
Fixing broken integration tests
1 parent a45aa4c commit dc33b5c

File tree

1 file changed

+25
-52
lines changed

1 file changed

+25
-52
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)

0 commit comments

Comments
 (0)