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()); }
/** * @param \Ikwattro\GuzzleStereo\Recorder * * @return callable */ public static function record(Recorder $recorder) { return function (callable $handler) use($recorder) { return function ($request, array $options) use($handler, $recorder) { return $handler($request, $options)->then(function ($response) use($request, $recorder) { $recorder->record($response); return $response; }, function ($reason) use($request, $recorder) { $response = $reason instanceof RequestException ? $reason->getResponse() : null; if ($response) { $recorder->record($response); } return \GuzzleHttp\Promise\rejection_for($reason); }); }; }; }
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); }
private function assertTapeExist($tape) { $this->assertInstanceOf('Ikwattro\\GuzzleStereo\\Record\\Tape', $this->recorder->getTape($tape)); $this->assertEquals($tape, $this->recorder->getTape($tape)->getName()); }
public function onKernelFinishRequest(FinishRequestEvent $event) { $this->recorder->dump(); }