Skip to content

Commit 7094e66

Browse files
GaryPEGEOTdbu
authored andcommitted
[Plugin] Add VCR Record & Replay plugins (#3)
* [Plugin] Add VCR Record & Replay plugins
1 parent ae671f6 commit 7094e66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+725
-1378
lines changed

.php_cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ $ composer require --dev php-http/vcr-plugin
2323

2424
## Usage
2525

26+
```php
27+
<?php
28+
29+
use Http\Client\Plugin\Vcr\NamingStrategy\PathNamingStrategy;
30+
use Http\Client\Plugin\Vcr\Recorder\FilesystemRecorder;
31+
use Http\Client\Plugin\Vcr\RecordPlugin;
32+
use Http\Client\Plugin\Vcr\ReplayPlugin;
33+
34+
$namingStrategy = new PathNamingStrategy();
35+
$recorder = new FilesystemRecorder('some/dir/in/vcs'); // You can use InMemoryRecorder as well
36+
37+
// To record responses:
38+
$record = new RecordPlugin($namingStrategy, $recorder);
39+
40+
// To replay responses:
41+
$replay = new ReplayPlugin($namingStrategy, $recorder);
42+
```
2643

2744
## Testing
2845

composer.json

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,36 @@
66
"homepage": "http://httplug.io",
77
"authors": [
88
{
9-
"name": "Jérôme Gamez",
10-
"email": "[email protected]"
9+
"name": "Gary PEGEOT",
10+
"email": "[email protected]"
1111
}
1212
],
1313
"require": {
14-
"php": "^5.6|^7.0",
15-
"php-http/plugins": "^1.0",
16-
"guzzlehttp/psr7": "^1.2"
14+
"php": "^7.1",
15+
"guzzlehttp/psr7": "^1.4",
16+
"php-http/client-common": "^2.0",
17+
"psr/log": "^1.0",
18+
"symfony/filesystem": "^3.4|^4.0",
19+
"symfony/options-resolver": "^3.4|^4.0"
1720
},
1821
"require-dev": {
19-
"phpunit/phpunit": "^5.2",
20-
"mikey179/vfsStream": "^1.6"
22+
"symfony/phpunit-bridge": ">= 4.2",
23+
"friendsofphp/php-cs-fixer": "^2.14"
2124
},
2225
"autoload": {
2326
"psr-4": {
2427
"Http\\Client\\Plugin\\Vcr\\": "src"
2528
}
2629
},
27-
"scripts": {
28-
"test": "vendor/bin/phpunit",
29-
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
30-
},
31-
"config": {
32-
"platform": {
33-
"php": "5.6"
30+
"autoload-dev": {
31+
"psr-4": {
32+
"Http\\Client\\Plugin\\Vcr\\Tests\\": "tests"
3433
}
3534
},
35+
"scripts": {
36+
"test": "vendor/bin/simple-phpunit",
37+
"test-ci": "vendor/bin/simple-phpunit --coverage-text --coverage-clover=build/coverage.xml"
38+
},
3639
"extra": {
3740
"branch-alias": {
3841
"dev-master": "1.0-dev"

phpunit.xml.dist

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
5-
bootstrap="tests/bootstrap.php"
6-
forceCoversAnnotation="true"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
5+
bootstrap="vendor/autoload.php"
76
colors="true">
87
<testsuites>
98
<testsuite name="VCR Plugin Test Suite">
@@ -13,7 +12,7 @@
1312

1413
<filter>
1514
<whitelist>
16-
<directory suffix=".php">.</directory>
15+
<directory suffix=".php">src</directory>
1716
<exclude>
1817
<directory>./tests</directory>
1918
<directory>./vendor</directory>

src/Exception/CannotBeReplayed.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Exception/InvalidState.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Exception/NotFound.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Exception/Storage.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Exception/VcrException.php

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Http\Client\Plugin\Vcr\NamingStrategy;
6+
7+
use Psr\Http\Message\RequestInterface;
8+
9+
/**
10+
* Provides a deterministic and unique identifier for a request. The identifier must be safe to use with a filesystem.
11+
*
12+
* @author Gary PEGEOT <[email protected]>
13+
*/
14+
interface NamingStrategyInterface
15+
{
16+
public function name(RequestInterface $request): string;
17+
}

0 commit comments

Comments
 (0)