Skip to content

Commit 3904a79

Browse files
committed
Merge pull request #1 from lapistano/whiteAndBlacklisting
White and blacklisting
2 parents 726ca26 + 68fe134 commit 3904a79

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

documentation/_posts/2013-10-20-configuration.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,49 @@ PHP-VCR can be configured by calling it's `configure` method which returns a `Co
1616
\VCR\VCR::configure()->enableLibraryHooks(array('curl_rewrite', 'soap'));
1717
\VCR\VCR::turnOn();
1818

19+
1920
Library hooks can only intercept HTTP requests if PHP-VCR is turned on right after initializing your autoloader, before the actual class to be replaced is loaded.
20-
Once loaded php-vcr does not have any change to do its' magic and intercept any request and/or response invoked by this class.
21+
Once loaded php-vcr does not have any change to do its' magic and intercept any request and/or response invoked by this class.
22+
2123

2224
## Request matching
2325

2426
In order to replay previously recorded requests, PHP-VCR must match new HTTP requests to a recorded one. By default, it matches all aspects of a HTTP request to fully identify the resource and action. Available request matchers are:
2527

2628
* `method` matches the HTTP method like GET, POST, ...
27-
* `url` matches the URI
29+
* `url` matches the URI
2830
* `host` matches the host name
2931
* `headers` matches all headers
3032
* `body` matches the request body
3133
* `post_fields` matches any post fields
3234

33-
You can customize how PHP-VCR matches requests using the configuration option. List every name of a matcher that should be enabled.
35+
You can customize how PHP-VCR matches requests using the configuration option. List every name of a matcher that should be enabled.
3436

3537
\VCR\\VCR::configue()
3638
->enableRequestMatchers(array('method', 'url', 'host'));
3739

3840
PHP-VCR allows you to define your own request matchers as callback functions and combine them with existing ones.
3941

4042
\VCR\\VCR::configue()
41-
->addRequestMatcher('custom_matcher',function (\VCR\Request $first, \VCR\Request $second) {
42-
// custom request matching
43-
return true;
44-
})
43+
->addRequestMatcher(
44+
'custom_matcher',
45+
function (\VCR\Request $first, \VCR\Request $second) {
46+
// custom request matching
47+
return true;
48+
}
49+
)
4550
->enableRequestMatchers(array('method', 'url', 'custom_matcher'));
4651

52+
## White- and Blacklisting methods
53+
54+
In special occasions, like a dedicated test scenario, you might want to exclude (blacklisting) or especially include (whitelisting) one or more methods throughout the test execution.
55+
This can be achieved by registering the name of the methods to either the recognized blacklist:
56+
57+
\VCR\VCR::configure()->setBlackList(array('NameOfTheSpecialMethod'));
58+
59+
or the provided whitelist:
4760

61+
VCR\VCR::configure()->setWhiteList(array('NameOfTheSpecialMethod'));
4862

63+
You certainly can use both in one setup, but be aware that a method set in the whitelist rules out the same method added to the blacklist and will be processed even when added to the blacklist.
64+
Both methods (setBlacklist() and setWhiteList()) do also follow the fluent interface paradigm mentioned above.

0 commit comments

Comments
 (0)