php-vcr/vcr-bundle
Composer 安装命令:
composer require php-vcr/vcr-bundle
包简介
Integrates php-vcr into Symfony and its web profiler.
README 文档
README
Integrates php-vcr into Symfony and its web profiler.
Supported: PHP 8.1–8.5 · Symfony 5.4 / 6.4 It also provides a VideoRecorderBrowser for testing purpose with extra helper methods handling php-vcr recordings.
Installation
Install the behavior adding php-vcr/vcr-bundle to your composer.json or
from CLI:
composer require php-vcr/vcr-bundle
And declare the bundle in your config/bundles.php file:
<?php declare(strict_types = 1); return [ // ... VCR\VCRBundle\VCRBundle::class => ['test' => true], ];
Usage
Enable the required library hooks for your purpose and write test cases.
VideoRecorderBrowser (without Trait)
<?php declare(strict_types = 1); class ExampleTest extends \VCR\VCRBundle\Tests\Functional\WebTestCase { public function test(): void { $kernel = static::bootKernel(); /** @var \VCR\VCRBundle\VideoRecorderBrowser $client */ $client = $kernel->getContainer()->get('test.client.vcr'); $client->insertVideoRecorderCassette('my-test-cassette-name'); // this is an example, normally services inside you project do stuff like this and you trigger them by // execute requests via the KernelBrowser client file_get_contents('https://www.google.de'); // cassette.path is configured to '%kernel.project_dir%/tests/Fixtures' // recordings are written to %kernel.project_dir%/tests/Fixtures/my-test-cassette-name // cassette.path + cassetteName (done by inserting the cassette) } }
VideoRecorderBrowser (with Trait)
<?php declare(strict_types = 1); namespace MyCompany\MyProject\Tests\Functional; class ExampleTest extends \VCR\VCRBundle\Tests\Functional\WebTestCase { use \VCR\VCRBundle\Test\VCRTestCaseTrait; /** * Specify a namespace prefix which should be ignored while generating the base path for this test case. */ protected $ignoredTestSuiteNamespacePrefix = 'MyCompany\\MyProject\\Tests\\'; public function test(): void { /** @var \VCR\VCRBundle\VideoRecorderBrowser $client */ $client = static::createVideoRecorderClient(); // this is an example, normally services inside you project do stuff like this and you trigger them by // execute requests via the KernelBrowser client file_get_contents('https://www.google.de'); // cassette.path is configured to '%kernel.project_dir%/tests/Fixtures' // recordings are written to %kernel.project_dir%/tests/Fixtures/Functional/ExampleTest/test // cassette.path + TestCasePath (- ignoredTestSuiteNamespacePrefix) + TestName } }
Configuration reference
vcr: enabled: true library_hooks: stream_wrapper: false curl: false soap: false request_matchers: method: true url: true query_string: true host: true headers: true body: true post_fields: true cassette: type: json path: '%kernel.cache_dir%/vcr' name: vcr
Credits
- Kévin Gomez
- Ludovic Fleury - to whom I borrowed the design of the web profiler part from his GuzzleBundle.
- Simon Hübner - making the bundle SF 5.4 / 6.4 and PHP 8.3–8.5 compatible
- Daniel Hürtgen - making the bundle PHP 8 compatible and providing extra TestCase helper
License
This bundle is released under the MIT license.
php-vcr/vcr-bundle 适用场景与选型建议
php-vcr/vcr-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26.92k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2014 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 php-vcr/vcr-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 php-vcr/vcr-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 26.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-26


