Skip to content

Commit

Permalink
Merge 801d787 into 2a9c3fc
Browse files Browse the repository at this point in the history
  • Loading branch information
adri committed Jan 31, 2014
2 parents 2a9c3fc + 801d787 commit d9b2ed3
Show file tree
Hide file tree
Showing 42 changed files with 616 additions and 790 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ before_script:

script:
- mkdir -p build/logs
- phpunit --exclude-group runkit --coverage-clover build/logs/clover.xml tests
- phpunit --coverage-clover build/logs/clover.xml tests

after_script:
- php vendor/bin/coveralls
6 changes: 3 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Disclaimer: Doing this in PHP is not as easy as in programming languages which s
* Supports common http functions and extensions
* everyting using [streamWrapper](http://php.net/manual/en/class.streamwrapper.php): fopen(), fread(), file_get_contents(), ... without any modification
* [SoapClient](http://www.php.net/manual/en/soapclient.soapclient.php) by adding `\VCR\VCR\turnOn();` in your `tests/boostrap.php`
* curl(), either using [runkit extension](http://www.php.net/manual/en/book.runkit.php) and `runkit.internal_override=1` in your php.ini or by adding `\VCR\VCR\turnOn();` in your `tests/boostrap.php`
* curl(), by adding `\VCR\VCR::turnOn();` in your `tests/boostrap.php`
* The same request can receive different responses in different tests--just use different cassettes.
* Disables all HTTP requests that you don't explicitly allow (except SoapClient if not configured).
* Request matching is configurable based on HTTP method, URI, host, path, body and headers, or you can easily
Expand Down Expand Up @@ -108,9 +108,8 @@ PHP-VCR depends on:
* HTTP library [Guzzle](http://guzzlephp.org)
* [symfony/yaml](https://github.com/symfony/yaml)
* [beberlei/assert](https://github.com/beberlei/assert)
* (optional) runkit extension with `runkit.internal_override=1` in php.ini if you want to intercept curl

Composer installs all dependencies except extensions like curl or runkit.
Composer installs all dependencies except extensions like curl.

## Run tests

Expand All @@ -123,6 +122,7 @@ phpunit ./tests

## Changelog

* 2014-01-28 Release 1.1.0: Removes curl runkit library hook.
* 2014-01-12 Release 1.0.6: Updates dependencies.
* 2013-10-13 Release 1.0.5: Fixed SOAP support, refactorings.
* 2013-07-22 Release 1.0.4: Updates dependencies.
Expand Down
4 changes: 0 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
"lapistano/proxy-object": "dev-master"
},

"suggest": {
"ext-runkit": "*"
},

"autoload": {
"classmap": ["src/"]
}
Expand Down
61 changes: 57 additions & 4 deletions src/VCR/Cassette.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,58 @@

namespace VCR;

use VCR\Storage\StorageInterface;
use VCR\Storage\Storage;
use VCR\Util\Assertion;

/**
* A Cassette records and plays back pairs of Requests and Responses in a Storage.
*/
class Cassette
{
/**
* Casette name
* @var string
*/
protected $name;

/**
* VCR configuration.
*
* @var Configuration
*/
protected $config;

/**
* Storage used to store records and request pairs.
*
* @var Storage
*/
protected $storage;
protected $cassetteHandle;

public function __construct($name, Configuration $config, StorageInterface $storage)
/**
* Creates a new cassette.
*
* @param string $name Name of the cassette.
* @param Configuration $config Configuration to use for this cassette.
* @param Storage $storage Storage to use for requests and responses.
* @throws \VCR\VCRException If cassette name is in an invalid format.
*/
public function __construct($name, Configuration $config, Storage $storage)
{
Assertion::string($name, "Cassette name must be a string, " . \gettype($name) . " given.");

$this->name = $name;
$this->config = $config;
$this->storage = $storage;
}

/**
* Returns true if a response was recorded for specified request.
*
* @param Request $request Request to check if it was recorded.
*
* @return boolean True if a response was recorded for specified request.
*/
public function hasResponse(Request $request)
{
return $this->playback($request) !== null;
Expand All @@ -29,6 +63,7 @@ public function hasResponse(Request $request)
* Returns a response for given request or null if not found.
*
* @param Request $request Request.
*
* @return string Response for specified request.
*/
public function playback(Request $request)
Expand All @@ -43,7 +78,15 @@ public function playback(Request $request)
return null;
}

public function record(Request $request, $response)
/**
* Records a request and response pair.
*
* @param Request $request Request to record.
* @param Response $response Response to record.
*
* @return void
*/
public function record(Request $request, Response $response)
{
if ($this->hasResponse($request)) {
return;
Expand All @@ -57,11 +100,21 @@ public function record(Request $request, $response)
$this->storage->storeRecording($recording);
}

/**
* Returns the name of the current cassette.
*
* @return string Current cassette name.
*/
public function getName()
{
return $this->name;
}

/**
* Returns a list of callbacks to configured request matchers.
*
* @return array List of callbacks to configured request matchers.
*/
protected function getRequestMatchers()
{
return $this->config->getRequestMatchers();
Expand Down
29 changes: 0 additions & 29 deletions src/VCR/Client.php

This file was deleted.

9 changes: 5 additions & 4 deletions src/VCR/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace VCR;

use VCR\Util\Assertion;

/**
* Configuration.
*/
Expand All @@ -10,11 +12,10 @@ class Configuration
private $cassettePath = 'tests/fixtures';

// All are enabled by default
private $enabledLibraryHooks = array('stream_wrapper', 'curl_rewrite', 'soap');
private $enabledLibraryHooks;
private $availableLibraryHooks = array(
'stream_wrapper' => 'VCR\LibraryHooks\StreamWrapper',
'curl_runkit' => 'VCR\LibraryHooks\CurlRunkit',
'curl_rewrite' => 'VCR\LibraryHooks\CurlRewrite',
'curl' => 'VCR\LibraryHooks\Curl',
'soap' => 'VCR\LibraryHooks\Soap',
);

Expand All @@ -36,7 +37,7 @@ class Configuration
'post_fields' => array('VCR\RequestMatcher', 'matchPostFields'),
);
private $whiteList = array();
private $blackList = array('src/VCR/LibraryHooks/', 'src/VCR/Util/Soap/SoapClient');
private $blackList = array('src/VCR/LibraryHooks/', 'src/VCR/Util/SoapClient');

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

namespace VCR\LibraryHooks;
namespace VCR\Filter;


abstract class AbstractFilter extends \PHP_User_Filter implements FilterInterface
abstract class AbstractFilter extends \PHP_User_Filter
{
const NAME = 'vcr_abstract_filter';

Expand Down
42 changes: 42 additions & 0 deletions src/VCR/Filter/CurlFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace VCR\Filter;

class CurlFilter extends AbstractFilter
{
const NAME = 'vcr_curl';

private static $replacements = array(
'\VCR\LibraryHooks\Curl::curl_init(',
'\VCR\LibraryHooks\Curl::curl_exec(',
'\VCR\LibraryHooks\Curl::curl_getinfo(',
'\VCR\LibraryHooks\Curl::curl_setopt(',
'\VCR\LibraryHooks\Curl::curl_setopt_array(',
'\VCR\LibraryHooks\Curl::curl_multi_add_handle(',
'\VCR\LibraryHooks\Curl::curl_multi_remove_handle(',
'\VCR\LibraryHooks\Curl::curl_multi_exec(',
'\VCR\LibraryHooks\Curl::curl_multi_info_read('
);

private static $patterns = array(
'@curl_init\s*\(@i',
'@curl_exec\s*\(@i',
'@curl_getinfo\s*\(@i',
'@curl_setopt\s*\(@i',
'@curl_setopt_array\s*\(@i',
'@curl_multi_add_handle\s*\(@i',
'@curl_multi_remove_handle\s*\(@i',
'@curl_multi_exec\s*\(@i',
'@curl_multi_info_read\s*\(@i',
);

/**
* @param string $code
*
* @return mixed
*/
protected function transformCode($code)
{
return preg_replace(self::$patterns, self::$replacements, $code);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?php

namespace VCR\LibraryHooks\Soap;
namespace VCR\Filter;

use VCR\LibraryHooks\AbstractFilter;

class Filter extends AbstractFilter
class SoapFilter extends AbstractFilter
{
const NAME = 'vcr_soap';

private static $replacements = array(
'new \VCR\Util\Soap\SoapClient(',
'extends \VCR\Util\Soap\SoapClient',
'new \VCR\Util\SoapClient(',
'extends \VCR\Util\SoapClient',
);

private static $patterns = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

namespace VCR\LibraryHooks;

use VCR\Util\Assertion;
use VCR\Request;
use VCR\Response;
use VCR\Assertion;
use VCR\Filter\AbstractFilter;
use VCR\Util\CurlHelper;
use VCR\Util\StreamProcessor;

/**
* Library hook for curl functions using include-overwrite.
*/
class CurlRewrite implements LibraryHookInterface
class Curl implements LibraryHook
{

/**
Expand Down Expand Up @@ -47,7 +48,7 @@ class CurlRewrite implements LibraryHookInterface
protected static $multiExecLastCh;

/**
* @var FilterInterface
* @var AbstractFilter
*/
private $filter;

Expand All @@ -60,7 +61,7 @@ class CurlRewrite implements LibraryHookInterface
*
* @throws \BadMethodCallException in case the Soap extension is not installed.
*/
public function __construct(FilterInterface $filter, StreamProcessor $processor)
public function __construct(AbstractFilter $filter, StreamProcessor $processor)
{
$this->processor = $processor;
$this->filter = $filter;
Expand Down Expand Up @@ -100,6 +101,14 @@ public function disable()
static::$status = self::DISABLED;
}

/**
* @inheritDoc
*/
public function isEnabled()
{
return $this->status == self::ENABLED;
}

/**
* Calls default curl functions if library hook is disabled.
*
Expand Down
44 changes: 0 additions & 44 deletions src/VCR/LibraryHooks/CurlRewrite/Filter.php

This file was deleted.

Loading

0 comments on commit d9b2ed3

Please sign in to comment.