{"id":13789753,"url":"https://github.com/php-vcr/php-vcr","last_synced_at":"2025-05-14T06:13:09.559Z","repository":{"id":6983852,"uuid":"8245842","full_name":"php-vcr/php-vcr","owner":"php-vcr","description":"Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.","archived":false,"fork":false,"pushed_at":"2024-07-15T13:29:34.000Z","size":1210,"stargazers_count":1169,"open_issues_count":82,"forks_count":201,"subscribers_count":29,"default_branch":"master","last_synced_at":"2024-10-29T15:24:04.628Z","etag":null,"topics":["accurate-tests","api-test","api-testing","deterministic","guzzle-services","guzzle-test","php","php-vcr","phpunit","replay","rest-test","restful-test","soap-api","soap-api-test","soap-test","test-automation","test-webservices","vcr","webservice","webservices"],"latest_commit_sha":null,"homepage":"http://php-vcr.github.io","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-vcr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-02-17T04:13:19.000Z","updated_at":"2024-10-29T14:30:21.000Z","dependencies_parsed_at":"2023-09-27T07:28:58.115Z","dependency_job_id":"3fc6bb17-ff86-42f0-8155-73d30cdc0136","html_url":"https://github.com/php-vcr/php-vcr","commit_stats":{"total_commits":698,"total_committers":73,"mean_commits":9.561643835616438,"dds":"0.49570200573065903","last_synced_commit":"045d02c8c6797b7b04b44be68e27d9248ac62977"},"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-vcr%2Fphp-vcr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-vcr%2Fphp-vcr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-vcr%2Fphp-vcr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-vcr%2Fphp-vcr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-vcr","download_url":"https://codeload.github.com/php-vcr/php-vcr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254081220,"owners_count":22011584,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accurate-tests","api-test","api-testing","deterministic","guzzle-services","guzzle-test","php","php-vcr","phpunit","replay","rest-test","restful-test","soap-api","soap-api-test","soap-test","test-automation","test-webservices","vcr","webservice","webservices"],"created_at":"2024-08-03T22:00:32.573Z","updated_at":"2025-05-14T06:13:09.496Z","avatar_url":"https://github.com/php-vcr.png","language":"PHP","readme":"![PHP-VCR](https://user-images.githubusercontent.com/133832/27151811-0d95c6c4-514c-11e7-834e-eff1eec2ea16.png)\n\n[![Continuous Integration](https://github.com/php-vcr/php-vcr/actions/workflows/continuous%20integration.yml/badge.svg?branch=master)](https://github.com/php-vcr/php-vcr/actions/workflows/continuous%20integration.yml)\n[![Code Coverage](https://scrutinizer-ci.com/g/php-vcr/php-vcr/badges/coverage.png?s=15cf1644c8cf37a868e03cfba809a5e24c78f285)](https://scrutinizer-ci.com/g/php-vcr/php-vcr/)\n[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/php-vcr/php-vcr/badges/quality-score.png?s=4f638dbca5eb51fb9c87a1dd45c5df94687d85bd)](https://scrutinizer-ci.com/g/php-vcr/php-vcr/)\n\nThis is a port of the [VCR](http://github.com/vcr/vcr) Ruby library to PHP.\n\nRecord your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests. A bit of documentation can be found on the [php-vcr website](http://php-vcr.github.io).\n\nDisclaimer: Doing this in PHP is not as easy as in programming languages which support monkey patching (I'm looking at you, Ruby)\n\n## Features\n\n* Automatically records and replays your HTTP(s) interactions with minimal setup/configuration code.\n* Supports common http functions and extensions\n  * everything using [streamWrapper](http://php.net/manual/en/class.streamwrapper.php): fopen(), fread(), file_get_contents(), ... without any modification (except `$http_response_header` see [#96](https://github.com/php-vcr/php-vcr/issues/96))\n  * [SoapClient](http://www.php.net/manual/en/soapclient.soapclient.php) by adding `\\VCR\\VCR::turnOn();` in your `tests/bootstrap.php`\n  * curl(), by adding `\\VCR\\VCR::turnOn();` in your `tests/bootstrap.php`\n* The same request can receive different responses in different tests -- just use different cassettes.\n* Disables all HTTP requests that you don't explicitly allow by [setting the record mode](http://php-vcr.github.io/documentation/configuration/)\n* [Request matching](http://php-vcr.github.io/documentation/configuration/) is configurable based on HTTP method, URI, host, path, body and headers, or you can easily\n  implement a custom request matcher to handle any need.\n* The recorded requests and responses are stored on disk in a serialization format of your choice\n  (currently YAML and JSON are built in, and you can easily implement your own custom serializer)\n* Supports PHPUnit annotations.\n\n## Usage example\n\nUsing static method calls:\n\n``` php\nclass VCRTest extends TestCase\n{\n    public function testShouldInterceptStreamWrapper()\n    {\n        // After turning on the VCR will intercept all requests\n        \\VCR\\VCR::turnOn();\n\n        // Record requests and responses in cassette file 'example'\n        \\VCR\\VCR::insertCassette('example');\n\n        // Following request will be recorded once and replayed in future test runs\n        $result = file_get_contents('http://example.com');\n        $this-\u003eassertNotEmpty($result);\n\n        // To stop recording requests, eject the cassette\n        \\VCR\\VCR::eject();\n\n        // Turn off VCR to stop intercepting requests\n        \\VCR\\VCR::turnOff();\n    }\n\n    public function testShouldThrowExceptionIfNoCasettePresent()\n    {\n        $this-\u003esetExpectedException(\n            'BadMethodCallException',\n            \"Invalid http request. No cassette inserted. Please make sure to insert \"\n            . \"a cassette in your unit test using VCR::insertCassette('name');\"\n        );\n        \\VCR\\VCR::turnOn();\n        // If there is no cassette inserted, a request throws an exception\n        file_get_contents('http://example.com');\n    }\n}\n```\n\nYou can use annotations in PHPUnit by using [phpunit-testlistener-vcr](https://github.com/php-vcr/phpunit-testlistener-vcr):\n\n``` php\nclass VCRTest extends TestCase\n{\n    /**\n     * @vcr unittest_annotation_test\n     */\n    public function testInterceptsWithAnnotations()\n    {\n        // Requests are intercepted and stored into  tests/fixtures/unittest_annotation_test.\n        $result = file_get_contents('http://google.com');\n\n        $this-\u003eassertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using annotations).');\n\n        // VCR is automatically turned on and off.\n    }\n}\n```\n\n## Installation\n\nSimply run the following command:\n\n``` bash\n$ composer require --dev php-vcr/php-vcr\n```\n\n## Dependencies\n\nPHP-VCR depends on:\n\n  * PHP 8\n  * Curl extension\n  * [symfony/event-dispatcher](https://github.com/symfony/event-dispatcher)\n  * [symfony/yaml](https://github.com/symfony/yaml)\n  * [beberlei/assert](https://github.com/beberlei/assert)\n\nComposer installs all dependencies except extensions like curl.\n\n## Run tests\n\nIn order to run all tests you need to get development dependencies using composer:\n\n``` php\ncomposer install\ncomposer test\n```\n\n## Changelog\n\n**The changelog has moved to the [PHP-VCR releases page](https://github.com/php-vcr/php-vcr/releases).**\n\n[Old changelog entries](docs/old-changelog.md)\n\n## Copyright\nCopyright (c) 2013-2023 Adrian Philipp. Released under the terms of the MIT license. See LICENSE for details.\n[Contributors](https://github.com/php-vcr/php-vcr/graphs/contributors)\n\n\u003c!--\nname of the projects and all sub-modules and libraries (sometimes they are named different and very confusing to new users)\ndescriptions of all the project, and all sub-modules and libraries\n5-line code snippet on how its used (if it's a library)\ncopyright and licensing information (or \"Read LICENSE\")\ninstruction to grab the documentation\ninstructions to install, configure, and to run the programs\ninstruction to grab the latest code and detailed instructions to build it (or quick overview and \"Read INSTALL\")\nlist of authors or \"Read AUTHORS\"\ninstructions to submit bugs, feature requests, submit patches, join mailing list, get announcements, or join the user or dev community in other forms\nother contact info (email address, website, company name, address, etc)\na brief history if it's a replacement or a fork of something else\nlegal notices (crypto stuff)\n--\u003e\n","funding_links":[],"categories":["PHP"],"sub_categories":["Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-vcr%2Fphp-vcr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-vcr%2Fphp-vcr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-vcr%2Fphp-vcr/lists"}