Exemple #1
0
 /**
  * Creates a new file store.
  *
  * If the cassetteName contains PATH_SEPARATORs, subfolders of the
  * cassettePath are autocreated when not existing.
  *
  * @param string  $cassettePath   Path to the cassette directory.
  * @param string  $cassetteName   Path to the cassette file, relative to the path.
  * @param string  $defaultContent Default data for this cassette if its not existing
  */
 public function __construct($cassettePath, $cassetteName, $defaultContent = '[]')
 {
     Assertion::directory($cassettePath, "Cassette path '{$cassettePath}' is not existing or not a directory");
     $this->filePath = rtrim($cassettePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $cassetteName;
     if (!is_dir(dirname($this->filePath))) {
         mkdir(dirname($this->filePath), 0777, true);
     }
     if (!file_exists($this->filePath) || 0 === filesize($this->filePath)) {
         file_put_contents($this->filePath, $defaultContent);
         $this->isNew = true;
     }
     Assertion::file($this->filePath, "Specified path '{$this->filePath}' is not a file.");
     Assertion::readable($this->filePath, "Specified file '{$this->filePath}' must be readable.");
     $this->handle = fopen($this->filePath, 'r+');
 }
Exemple #2
0
 /**
  * Validates a specified cassette path.
  *
  * @param string $cassettePath Path to a cassette.
  * @throws VCRException If cassette path is invalid.
  */
 private function assertValidCassettePath($cassettePath)
 {
     Assertion::directory($cassettePath, "Cassette path '{$cassettePath}' is not a directory. Please either " . "create it or set a different cassette path using " . "\\VCR\\VCR::configure()->setCassettePath('directory').");
 }