2017 © Pedro Peláez
 

library tape-recorder-subscriber

Record HTTP interactions to replay them later with the Tape Recorder Subscriber for the Ivory HTTP Adapter

image

kreait/tape-recorder-subscriber

Record HTTP interactions to replay them later with the Tape Recorder Subscriber for the Ivory HTTP Adapter

  • Wednesday, August 3, 2016
  • by jeromegamez
  • Repository
  • 3 Watchers
  • 2 Stars
  • 602 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 1 % Grown

The README.md

Tape Recorder Subscriber for the Ivory HTTP Adapter

The Tape Recorder Subscriber for the Ivory HTTP Adapter works similarly to the php-vcr and also uses similar wordings :)., (*1)

With it, it is possible to record the HTTP interactions, e.g. in Unit Tests, store them as Fixture files and replay them in future runs., (*2)

An example fixture (actually used for such a test) can be found here: Example fixture., (*3)

Usage

use Ivory\HttpAdapter\EventDispatcherHttpAdapter;
use Ivory\HttpAdapter\HttpAdapterFactory;
use Kreait\Ivory\HttpAdapter\Event\Subscriber\TapeRecorderSubscriber;
use Symfony\Component\EventDispatcher\EventDispatcher;

$recorder = new TapeRecorderSubscriber(__DIR__.'/fixtures');

$eventDispatcher = new EventDispatcher();
$eventDispatcher->addSubscriber($this->recorder);

$http = new EventDispatcherHttpAdapter(
    HttpAdapterFactory::guess(),
    $eventDispatcher
);       

$recorder->insertTape('my_tape');
$recorder->startRecording();
$httpAdapter->get(...); // This interaction will be stored as a track.
$recorder->stopRecording;
$httpAdapter->get(...); // This interaction will not be stored.
$recorder->eject(); // Stores the tape to the file system
Recording modes
$recorder->setRecordingMode(...);

The following recording modes can be set when using the Tape Recorder:, (*4)

Mode Description
RECORDING_MODE_ONCE (default) Performs a real request and stores it to a fixture, unless a fixture already exists.
RECORDING_MODE_OVERWRITE Always performs a real request and overwrites the fixture.
RECORDING_MODE_NEVER Always performs a real request and does not write a fixture.
Usage example in Unit Tests
namespace My\Application\Tests;

use Ivory\HttpAdapter\EventDispatcherHttpAdapter;
use Ivory\HttpAdapter\HttpAdapterFactory;
use Kreait\Ivory\HttpAdapter\Event\Subscriber\TapeRecorderSubscriber;
use Symfony\Component\EventDispatcher\EventDispatcher;

class MyTest extends extends \PHPUnit_Framework_TestCase
{
    /** @var \Ivory\HttpAdapter\HttpAdapterInterface **/
    protected $http;

    /** @var TapeRecorderSubscriber */
    protected $recorder;

    protected function setUp()
    {
        $this->recorder = new TapeRecorderSubscriber(__DIR__.'/fixtures');

        $http = HttpAdapterFactory::guess();

        $eventDispatcher = new EventDispatcher();
        $eventDispatcher->addSubscriber($this->recorder);

        $this->http = new EventDispatcherHttpAdapter(
            $http, $eventDispatcher
        );
    }

    protected function tearDown()
    {
        $this->recorder->eject();
    }

    protected function testRequest()
    {
        // This will result in the file 'fixtures/testRequest.yml'
        $this->recorder->insertTape(__FUNCTION__);
        $this->recorder->startRecording();
        $this->http->get(...);
    }
}

The Versions

03/08 2016

dev-master

9999999-dev https://github.com/kreait/tape-recorder-subscriber

Record HTTP interactions to replay them later with the Tape Recorder Subscriber for the Ivory HTTP Adapter

  Sources   Download

MIT

The Requires

 

The Development Requires

16/07 2016

3.0.2

3.0.2.0 https://github.com/kreait/tape-recorder-subscriber

Record HTTP interactions to replay them later with the Tape Recorder Subscriber for the Ivory HTTP Adapter

  Sources   Download

MIT

The Requires

 

The Development Requires

08/12 2015

3.0.1

3.0.1.0 https://github.com/kreait/tape-recorder-subscriber

Record HTTP interactions to replay them later with the Tape Recorder Subscriber for the Ivory HTTP Adapter

  Sources   Download

MIT

The Requires

 

The Development Requires

13/08 2015

3.0

3.0.0.0 https://github.com/kreait/tape-recorder-subscriber

Record HTTP interactions to replay them later with the Tape Recorder Subscriber for the Ivory HTTP Adapter

  Sources   Download

MIT

The Requires

 

The Development Requires

11/04 2015

2.0.2

2.0.2.0 https://github.com/kreait/tape-recorder-subscriber

Record HTTP interactions to replay them later with the Tape Recorder Subscriber for the Ivory HTTP Adapter

  Sources   Download

MIT

The Requires

 

The Development Requires

11/04 2015

2.0.1

2.0.1.0 https://github.com/kreait/tape-recorder-subscriber

Record HTTP interactions to replay them later with the Tape Recorder Subscriber for the Ivory HTTP Adapter

  Sources   Download

MIT

The Requires

 

The Development Requires

11/04 2015

2.0

2.0.0.0 https://github.com/kreait/tape-recorder-subscriber

Record HTTP interactions to replay them later with the Tape Recorder Subscriber for the Ivory HTTP Adapter

  Sources   Download

MIT

The Requires

 

The Development Requires

23/02 2015

1.0

1.0.0.0

Record HTTP interactions to replay them later.

  Sources   Download

MIT

The Requires

 

The Development Requires