Ikwattro\GuzzleStereo\Recorder::dump PHP Method

dump() public method

Dumps the tapes on disk.
public dump ( )
    public function dump()
    {
        foreach ($this->tapes as $tape) {
            if ($tape->hasResponses()) {
                $fileName = 'record_' . $tape->getName() . '.json';
                $content = $this->formatter->encodeResponsesCollection($tape->getResponses());
                $this->writer->write($fileName, $content);
            }
        }
    }

Usage Example

 public function testRecorderIsDumpingTapes()
 {
     $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) {
         }
     }
     $this->recorder->dump();
     $successTapeFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'record_tape-success.json';
     $AllTapeFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'record_tape-all.json';
     $UnauthTapeFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'record_tape-unauthorized.json';
     $this->assertFileExists($successTapeFile);
     $this->assertFileExists($AllTapeFile);
     $this->assertFileExists($UnauthTapeFile);
 }
All Usage Examples Of Ikwattro\GuzzleStereo\Recorder::dump