Skip to content

Commit

Permalink
Merge pull request #247 from moufmouf/fix_integration_tests
Browse files Browse the repository at this point in the history
Fixing broken integration tests
  • Loading branch information
renatomefi committed Apr 12, 2018
2 parents a45aa4c + 9bad9fb commit 4087b41
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 59 deletions.
77 changes: 25 additions & 52 deletions tests/integration/guzzle/test/VCR/Example/ExampleHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class ExampleHttpClientTest extends \PHPUnit_Framework_TestCase
{
const TEST_GET_URL = 'http://httpbin.org/get';
const TEST_GET_URL = 'http://api.chew.pro/trbmb';
const TEST_POST_URL = 'http://httpbin.org/post';
const TEST_POST_BODY = '{"foo":"bar"}';

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

public function testRequestGETDirect()
public function testRequestGET()
{
$this->assertValidGETResponse($this->requestGET());
}

public function testRequestGETIntercepted()
{
$this->assertValidGETResponse($this->requestGETIntercepted());
}

public function testRequestGETDirectEqualsIntercepted()
{
$this->assertEquals($this->requestGET(), $this->requestGETIntercepted());
}

public function testRequestGETInterceptedIsRepeatable()
{
$this->assertEquals($this->requestGETIntercepted(), $this->requestGETIntercepted());
}

public function testRequestPOSTDirect()
{
$this->assertValidPOSTResponse($this->requestPOST());
}

public function testRequestPOSTIntercepted()
{
$this->assertValidPOSTResponse($this->requestPOSTIntercepted());
}

public function testRequestPOSTDirectEqualsIntercepted()
{
$this->assertEquals($this->requestPOST(), $this->requestPOSTIntercepted());
\VCR\VCR::turnOn();
\VCR\VCR::insertCassette('test-cassette.yml');
$originalRequest = $this->requestGET();
$this->assertValidGETResponse($originalRequest);
$interceptedRequest = $this->requestGET();
$this->assertValidGETResponse($interceptedRequest);
$this->assertEquals($originalRequest, $interceptedRequest);
$repeatInterceptedRequest = $this->requestGET();
$this->assertEquals($interceptedRequest, $repeatInterceptedRequest);
\VCR\VCR::turnOff();
}

public function testRequestPOSTInterceptedIsRepeatable()
public function testRequestPOST()
{
$this->assertEquals($this->requestPOSTIntercepted(), $this->requestPOSTIntercepted());
\VCR\VCR::turnOn();
\VCR\VCR::insertCassette('test-cassette.yml');
$originalRequest = $this->requestPOST();
$this->assertValidPOSTResponse($originalRequest);
$interceptedRequest = $this->requestPOST();
$this->assertValidPOSTResponse($interceptedRequest);
$this->assertEquals($originalRequest, $interceptedRequest);
$repeatInterceptedRequest = $this->requestPOST();
$this->assertEquals($interceptedRequest, $repeatInterceptedRequest);
\VCR\VCR::turnOff();
}

protected function requestGET()
{
$exampleClient = new ExampleHttpClient();

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

return $response;
}
Expand All @@ -86,20 +71,11 @@ protected function requestPOST()
foreach ($this->ignoreHeaders as $header) {
unset($response['headers'][$header]);
}
unset($response['origin']);

return $response;
}

protected function requestGETIntercepted()
{
\VCR\VCR::turnOn();
\VCR\VCR::insertCassette('test-cassette.yml');
$info = $this->requestGET();
\VCR\VCR::turnOff();

return $info;
}

protected function requestPOSTIntercepted()
{
\VCR\VCR::turnOn();
Expand All @@ -113,10 +89,7 @@ protected function requestPOSTIntercepted()
protected function assertValidGETResponse($info)
{
$this->assertInternalType('array', $info, 'Response is not an array.');
$this->assertArrayHasKey('url', $info, "Key 'url' not found.");
$this->assertEquals(self::TEST_GET_URL, $info['url'], "Value for key 'url' wrong.");
$this->assertArrayHasKey('headers', $info, "Key 'headers' not found.");
$this->assertInternalType('array', $info['headers'], 'Headers is not an array.');
$this->assertArrayHasKey('0', $info, 'API did not return any value.');
}

protected function assertValidPOSTResponse($info)
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/soap/src/VCR/Example/ExampleSoapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
*/
class ExampleSoapClient
{
const EXAMPLE_WSDL = 'http://www.webservicex.net/ConvertTemperature.asmx?WSDL';
const EXAMPLE_WSDL = 'http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL';

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

return (int) $response->ConvertTempResult;
return trim((string) $response->NumberToWordsResult);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ public function setUp()
public function testCallDirectly()
{
$actual = $this->callSoap();
$this->assertInternalType('integer', $actual);
$this->assertInternalType('string', $actual);
$this->assertEquals('twelve', $actual);
}

public function testCallIntercepted()
{
$actual = $this->callSoapIntercepted();
$this->assertInternalType('integer', $actual);
$this->assertInternalType('string', $actual);
$this->assertEquals('twelve', $actual);
}

public function testCallDirectlyEqualsIntercepted()
Expand All @@ -38,7 +40,7 @@ public function testCallDirectlyEqualsIntercepted()
protected function callSoap()
{
$soapClient = new ExampleSoapClient();
return $soapClient->call('10013'); // somewhere in New York
return $soapClient->call(12);
}

protected function callSoapIntercepted()
Expand Down

0 comments on commit 4087b41

Please sign in to comment.