Ikwattro\GuzzleStereo\Recorder::getTapeContent PHP Method

getTapeContent() public method

Returns the content of a specific tape without writing it to disk.
public getTapeContent ( string $name ) : null | string
$name string
return null | string
    public function getTapeContent($name)
    {
        $tape = $this->getTape($name);
        if ($tape->hasResponses()) {
            $content = $this->formatter->encodeResponsesCollection($tape->getResponses());
            return $content;
        }
        return;
    }

Usage Example

 public function testPlayerCanReplayFromContent()
 {
     $mock = SimpleMockHandler::create()->withMultipleResponses(5, 200)->withMultipleResponses(5, 403)->withMultipleResponses(5, 404)->build();
     $client = SimpleMockedClient::createMockedClient($mock, $this->recorder);
     for ($i = 0; $i < 15; $i++) {
         try {
             $client->get('/');
         } catch (RequestException $e) {
         }
     }
     $content = $this->recorder->getTapeContent('tape-all');
     $player = Player::replayFromContent($content);
     $this->assertInstanceOf('GuzzleHttp\\Client', $player->getClient());
     $this->assertEquals(200, $player->get('/')->getStatusCode());
 }