All Projects → php-vcr → Php Vcr

php-vcr / Php Vcr

Licence: mit
Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.

Projects that are alternatives of or similar to Php Vcr

Just Api
💥 Test REST, GraphQL APIs
Stars: ✭ 768 (-21.31%)
Mutual labels:  webservice, api-testing
replaykit.py
Python SDK for using Appetizer replaykit
Stars: ✭ 18 (-98.16%)
Mutual labels:  test-automation, replay
laravel-test-watcher
Laravel Test Watcher
Stars: ✭ 20 (-97.95%)
Mutual labels:  phpunit, test-automation
software-testing-resource-pack
Various files useful for manual testing and test automation etc.
Stars: ✭ 38 (-96.11%)
Mutual labels:  test-automation, api-testing
MAQS
Magenic's automation quick start
Stars: ✭ 46 (-95.29%)
Mutual labels:  webservice, test-automation
Metersphere
MeterSphere 是一站式开源持续测试平台,覆盖测试管理、接口测试、性能测试等。搞测试,就选 MeterSphere!
Stars: ✭ 6,331 (+548.67%)
Mutual labels:  api-testing, test-automation
karate
Test Automation Made Simple
Stars: ✭ 6,384 (+554.1%)
Mutual labels:  test-automation, api-testing
karate-runner
VSCode Extension for Karate
Stars: ✭ 23 (-97.64%)
Mutual labels:  test-automation, api-testing
irontest
A web app for API test automation
Stars: ✭ 31 (-96.82%)
Mutual labels:  test-automation, api-testing
apitest
Apitest is declarative api testing tool with JSON-like DSL.
Stars: ✭ 88 (-90.98%)
Mutual labels:  test-automation, api-testing
Karate
Test Automation Made Simple
Stars: ✭ 5,497 (+463.22%)
Mutual labels:  api-testing, test-automation
Sentence Aligner Rust
rest service + frontend to align sentences , in rust
Stars: ✭ 13 (-98.67%)
Mutual labels:  webservice
Replaylightshistory
AppDaemon App for Home Assistant to replay light switch history when no one is home.
Stars: ✭ 17 (-98.26%)
Mutual labels:  replay
Otrs
((OTRS)) Community Edition is one of the most flexible web-based ticketing systems used for Customer Service, Help Desk, IT Service Management. Please note that ((OTRS)) Community Edition offers limited OTRS functionality.
Stars: ✭ 769 (-21.21%)
Mutual labels:  webservice
Virtualmeter
A general develop framework for smart meter.
Stars: ✭ 31 (-96.82%)
Mutual labels:  test-automation
Chn Eolinker Ams Lite 4.0 For Php
中国最大的在线API管理平台EOLINKER 旗下API管理系统开源精简版,适合个人以及微型团队使用。
Stars: ✭ 869 (-10.96%)
Mutual labels:  api-testing
Repeat
Cross-platform mouse/keyboard record/replay and automation hotkeys/macros creation, and more advanced automation features.
Stars: ✭ 763 (-21.82%)
Mutual labels:  replay
Tavern
A command-line tool and Python library and Pytest plugin for automated testing of RESTful APIs, with a simple, concise and flexible YAML-based syntax
Stars: ✭ 760 (-22.13%)
Mutual labels:  test-automation
Tddd
A Laravel Continuous Integration Package
Stars: ✭ 722 (-26.02%)
Mutual labels:  phpunit
Ghpr.nunit
Adapter for NUnit 3 (generate HTML report for NUnit 3)
Stars: ✭ 33 (-96.62%)
Mutual labels:  test-automation

PHP-VCR

Build Status Code Coverage Scrutinizer Quality Score

This is a port of the VCR Ruby library to PHP.

Record 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.

Disclaimer: Doing this in PHP is not as easy as in programming languages which support monkey patching (I'm looking at you, Ruby)

Features

  • Automatically records and replays your HTTP(s) interactions with minimal setup/configuration code.
  • Supports common http functions and extensions
    • everything using streamWrapper: fopen(), fread(), file_get_contents(), ... without any modification (except $http_response_header see #96)
    • SoapClient by adding \VCR\VCR::turnOn(); in your tests/bootstrap.php
    • curl(), by adding \VCR\VCR::turnOn(); in your tests/bootstrap.php
  • The same request can receive different responses in different tests -- just use different cassettes.
  • Disables all HTTP requests that you don't explicitly allow by setting the record mode
  • Request matching is configurable based on HTTP method, URI, host, path, body and headers, or you can easily implement a custom request matcher to handle any need.
  • The recorded requests and responses are stored on disk in a serialization format of your choice (currently YAML and JSON are built in, and you can easily implement your own custom serializer)
  • Supports PHPUnit annotations.

Usage example

Using static method calls:

class VCRTest extends TestCase
{
    public function testShouldInterceptStreamWrapper()
    {
        // After turning on the VCR will intercept all requests
        \VCR\VCR::turnOn();

        // Record requests and responses in cassette file 'example'
        \VCR\VCR::insertCassette('example');

        // Following request will be recorded once and replayed in future test runs
        $result = file_get_contents('http://example.com');
        $this->assertNotEmpty($result);

        // To stop recording requests, eject the cassette
        \VCR\VCR::eject();

        // Turn off VCR to stop intercepting requests
        \VCR\VCR::turnOff();
    }

    public function testShouldThrowExceptionIfNoCasettePresent()
    {
        $this->setExpectedException(
            'BadMethodCallException',
            "Invalid http request. No cassette inserted. Please make sure to insert "
            . "a cassette in your unit test using VCR::insertCassette('name');"
        );
        \VCR\VCR::turnOn();
        // If there is no cassette inserted, a request throws an exception
        file_get_contents('http://example.com');
    }
}

You can use annotations in PHPUnit by using phpunit-testlistener-vcr:

class VCRTest extends TestCase
{
    /**
     * @vcr unittest_annotation_test
     */
    public function testInterceptsWithAnnotations()
    {
        // Requests are intercepted and stored into  tests/fixtures/unittest_annotation_test.
        $result = file_get_contents('http://google.com');

        $this->assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using annotations).');

        // VCR is automatically turned on and off.
    }
}

Installation

Simply run the following command:

$ composer require --dev php-vcr/php-vcr

Dependencies

PHP-VCR depends on:

Composer installs all dependencies except extensions like curl.

Run tests

In order to run all tests you need to get development dependencies using composer:

composer install
composer test

Changelog

The changelog has moved to the PHP-VCR releases page.

Old changelog entries

Copyright

Copyright (c) 2013-2016 Adrian Philipp. Released under the terms of the MIT license. See LICENSE for details. Contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].