Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix curl reset #248

Merged
merged 3 commits into from May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -30,6 +30,8 @@ matrix:
php: 5.6
- env: TEST_DIR=tests/integration/guzzle/5
php: 5.6
- env: TEST_DIR=tests/integration/guzzle/6
php: 5.6
- env: TEST_DIR=tests/integration/soap
php: 5.6

Expand All @@ -56,4 +58,5 @@ cache:
- tests/integration/guzzle/3/vendor
- tests/integration/guzzle/4/vendor
- tests/integration/guzzle/5/vendor
- tests/integration/guzzle/6/vendor
- $HOME/.composer/cache
1 change: 1 addition & 0 deletions src/VCR/LibraryHooks/CurlHook.php
Expand Up @@ -182,6 +182,7 @@ public static function curlReset($curlHandle)
\curl_reset($curlHandle);
self::$requests[(int) $curlHandle] = new Request('GET', null);
self::$curlOptions[(int) $curlHandle] = array();
unset(self::$responses[(int) $curlHandle]);
}

/**
Expand Down
41 changes: 41 additions & 0 deletions tests/integration/guzzle/6/ExampleHttpClient.php
@@ -0,0 +1,41 @@
<?php

namespace VCR\Example;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;

class ExampleHttpClient
{
public function get($url)
{
$client = new Client();

try {
$response = $client->get($url);
return json_decode($response->getBody(), true);
} catch (ClientException $e) {
if ($e->getCode() !== 404) {
throw $e;
}
}

return null;
}

public function post($url, $body)
{
$client = new Client();

try {
$response = $client->post($url, array('body' => $body));
return json_decode($response->getBody(), true);
} catch (ClientException $e) {
if ($e->getCode() !== 404) {
throw $e;
}
}

return null;
}
}
5 changes: 5 additions & 0 deletions tests/integration/guzzle/6/composer.json
@@ -0,0 +1,5 @@
{
"require": {
"guzzlehttp/guzzle": "~6.0"
}
}
15 changes: 15 additions & 0 deletions tests/integration/guzzle/6/phpunit.xml
@@ -0,0 +1,15 @@
<phpunit bootstrap="../test/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>

<testsuites>
<testsuite>
<directory>../test</directory>
<directory>test</directory>
</testsuite>
</testsuites>

</phpunit>
45 changes: 45 additions & 0 deletions tests/integration/guzzle/6/test/AsyncTest.php
@@ -0,0 +1,45 @@
<?php

namespace VCR\Example;

use GuzzleHttp\Client;
use org\bovigo\vfs\vfsStream;

/**
* Tests example request.
*/
class AsyncTest extends \PHPUnit_Framework_TestCase
{
const TEST_GET_URL = 'http://api.chew.pro/trbmb';
const TEST_GET_URL_2 = 'http://api.chew.pro/trbmb?foo=42';

public function setUp()
{
vfsStream::setup('testDir');
\VCR\VCR::configure()->setCassettePath(vfsStream::url('testDir'));
}

public function testAsyncLock()
{
\VCR\VCR::turnOn();
\VCR\VCR::insertCassette('test-cassette.yml');

$client = new Client();
$promise = $client->getAsync(self::TEST_GET_URL);
$response = $promise->wait();
$promise = $client->getAsync(self::TEST_GET_URL_2);
$promise->wait();
// Let's check that we can perform 2 async request on different URLs without locking.
// Solves https://github.com/php-vcr/php-vcr/issues/211

$this->assertValidGETResponse(\GuzzleHttp\json_decode($response->getBody()));

\VCR\VCR::turnOff();
}

protected function assertValidGETResponse($info)
{
$this->assertInternalType('array', $info, 'Response is not an array.');
$this->assertArrayHasKey('0', $info, 'API did not return any value.');
}
}