public function testStoreTape()
 {
     $tape = new Tape($name = 'foo', $path = sys_get_temp_dir() . '/' . uniqid());
     $tape->writeTrack($track = $this->createTrack('http://foo.bar/'));
     $tape->store();
     $this->assertFileExists($file = sprintf('%s/%s.yml', $path, $name));
     // Reload
     $tape->load();
     $this->assertCount(1, $tracks = $tape->getTracks());
     $check = $tape->getTrackForRequest($track->getRequest());
     $this->assertInstanceOf('Kreait\\Ivory\\HttpAdapter\\Event\\TapeRecorder\\Track', $check);
     // Test the non scalar attributes
     $this->assertEquals((string) $track->getRequest()->getUri(), (string) $check->getRequest()->getUri());
     $this->assertEquals((string) $track->getResponse()->getBody(), (string) $check->getResponse()->getBody());
     @unlink($file);
 }
 /**
  * We arrive here when the request has successfully been intercepted.
  *
  * @param RequestErroredEvent $event The exception event.
  */
 public function onException(RequestErroredEvent $event)
 {
     if (!$this->isRecording) {
         return;
     }
     $exception = $event->getException();
     $request = $exception->getRequest();
     if (!$this->currentTape->hasTrackForRequest($request)) {
         return;
     }
     $track = $this->currentTape->getTrackForRequest($request);
     if (!$exception instanceof TapeRecorderException) {
         // Normal exception, let's store it in the track for the next time
         $this->currentTape->finishRecording($track, $event->getResponse(), $event->getException());
         return;
     }
     // We are in replay mode
     if ($track->hasResponse()) {
         $event->setResponse($track->getResponse());
     }
     if ($track->hasException()) {
         $event->setException($track->getException());
     }
 }