@@ -3,6 +3,7 @@ VCRBundle
33
44Integrates [ php-vcr] ( https://github.com/php-vcr/php-vcr ) into Symfony and its
55web profiler.
6+ It also provides a VideoRecorderBrowser for testing purpose with extra helper methods handling php-vcr recordings.
67
78<img src =" https://cloud.githubusercontent.com/assets/66958/5232274/b841676e-774b-11e4-8f4e-1f3e8cb7739e.png " width =" 280 " height =" 175 " alt =" PHP-VCR Symfony web profiler panel " />
89<img src =" https://cloud.githubusercontent.com/assets/66958/5232275/b84288d8-774b-11e4-803c-7b72f75e59b0.png " width =" 280 " height =" 175 " alt =" PHP-VCR Symfony web profiler panel - request details " />
@@ -20,41 +21,109 @@ composer require php-vcr/vcr-bundle
2021And declare the bundle in your ` config/bundles.php ` file:
2122
2223``` php
24+ <?php
25+ declare(strict_types = 1);
26+
2327return [
2428 // ...
2529 VCR\VCRBundle\VCRBundle::class => ['test' => true],
2630];
31+ ```
32+
33+ ## Usage
34+
35+ Enable the required library hooks for your purpose and write test cases.
36+
37+ ### VideoRecorderBrowser (without Trait)
38+
39+ ``` php
40+ <?php
41+ declare(strict_types = 1);
42+
43+ class ExampleTest extends \VCR\VCRBundle\Tests\Functional\WebTestCase
44+ {
45+ public function test(): void
46+ {
47+ $kernel = static::bootKernel();
48+ /** @var \VCR\VCRBundle\VideoRecorderBrowser $client */
49+ $client = $kernel->getContainer()->get('test.client.vcr');
50+
51+ $client->insertVideoRecorderCassette('my-test-cassette-name');
52+
53+ // this is an example, normally services inside you project do stuff like this and you trigger them by
54+ // execute requests via the KernelBrowser client
55+ file_get_contents('https://www.google.de');
56+
57+ // cassette.path is configured to '%kernel.project_dir%/tests/Fixtures'
58+ // recordings are written to %kernel.project_dir%/tests/Fixtures/my-test-cassette-name
59+ // cassette.path + cassetteName (done by inserting the cassette)
60+ }
61+ }
62+ ```
63+
64+ ### VideoRecorderBrowser (with Trait)
65+
66+ ``` php
67+ <?php
68+ declare(strict_types = 1);
69+
70+ namespace MyCompany\MyProject\Tests\Functional;
71+
72+ class ExampleTest extends \VCR\VCRBundle\Tests\Functional\WebTestCase
73+ {
74+ use \VCR\VCRBundle\Test\VCRTestCaseTrait;
75+
76+ /**
77+ * Specify a namespace prefix which should be ignored while generating the base path for this test case.
78+ */
79+ protected $ignoredTestSuiteNamespacePrefix = 'MyCompany\\MyProject\\Tests\\';
2780
81+ public function test(): void
82+ {
83+ /** @var \VCR\VCRBundle\VideoRecorderBrowser $client */
84+ $client = static::createVideoRecorderClient();
85+
86+ // this is an example, normally services inside you project do stuff like this and you trigger them by
87+ // execute requests via the KernelBrowser client
88+ file_get_contents('https://www.google.de');
89+
90+ // cassette.path is configured to '%kernel.project_dir%/tests/Fixtures'
91+ // recordings are written to %kernel.project_dir%/tests/Fixtures/Functional/ExampleTest/test
92+ // cassette.path + TestCasePath (- ignoredTestSuiteNamespacePrefix) + TestName
93+ }
94+ }
2895```
2996
3097## Configuration reference
3198
3299``` yaml
33100vcr :
34- enabled : true
35- library_hooks :
36- stream_wrapper : false
37- curl : false
38- soap : false
39- request_matchers :
40- method : true
41- url : true
42- query_string : true
43- host : true
44- headers : true
45- body : true
46- post_fields : true
47- cassette :
48- type : json
49- path : ' %kernel.cache_dir%/vcr'
50- name : vcr
101+ enabled : true
102+ library_hooks :
103+ stream_wrapper : false
104+ curl : false
105+ soap : false
106+ request_matchers :
107+ method : true
108+ url : true
109+ query_string : true
110+ host : true
111+ headers : true
112+ body : true
113+ post_fields : true
114+ cassette :
115+ type : json
116+ path : ' %kernel.cache_dir%/vcr'
117+ name : vcr
51118` ` `
52119
53120## Credits
54121
55- * [Kévin Gomez](http://github.com/K-Phoen/)
56- * [Ludovic Fleury](https://github.com/ludofleury) - to whom I borrowed the
57- design of the web profiler part from his [GuzzleBundle](https://github.com/ludofleury/GuzzleBundle/).
122+ * [Kévin Gomez](http://github.com/K-Phoen/)
123+ * [Ludovic Fleury](https://github.com/ludofleury) - to whom I borrowed the
124+ design of the web profiler part from his [GuzzleBundle](https://github.com/ludofleury/GuzzleBundle/).
125+ * [Simon Hübner](https://github.com/simonhard) - making the bundle SF 5.4 compatible
126+ * [Daniel Hürtgen](https://github.com/higidi) - making the bundle PHP 8 compatible and providing extra TestCase helper
58127
59128## License
60129
0 commit comments