@@ -54,30 +54,29 @@ abstract class AbstractStorage implements Storage
5454 * If the cassetteName contains PATH_SEPARATORs, subfolders of the
5555 * cassettePath are autocreated when not existing.
5656 *
57- * @param string $cassettePath Path to the cassette directory.
58- * @param string $cassetteName Path to the cassette file, relative to the path.
57+ * @param string $cassettePath Path to the cassette directory.
58+ * @param string $cassetteName Path to the cassette file, relative to the path.
59+ * @param string $defaultContent Default data for this cassette if its not existing
5960 */
6061 public function __construct ($ cassettePath , $ cassetteName , $ defaultContent = '[] ' )
6162 {
6263 Assertion::directory ($ cassettePath , "Cassette path ' {$ cassettePath }' is not existing or not a directory " );
6364
64- $ file = rtrim ($ cassettePath , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $ cassetteName ;
65+ $ this -> filePath = rtrim ($ cassettePath , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $ cassetteName ;
6566
66- if (!is_dir (dirname ($ file ))) {
67- mkdir (dirname ($ file ), 0777 , true );
67+ if (!is_dir (dirname ($ this -> filePath ))) {
68+ mkdir (dirname ($ this -> filePath ), 0777 , true );
6869 }
6970
70- if (!file_exists ($ file ) || 0 === filesize ($ file )) {
71- file_put_contents ($ file , $ defaultContent );
72-
71+ if (!file_exists ($ this ->filePath ) || 0 === filesize ($ this ->filePath )) {
72+ file_put_contents ($ this ->filePath , $ defaultContent );
7373 $ this ->isNew = true ;
74+ } else {
75+ Assertion::file ($ this ->filePath , "Specified path ' {$ this ->filePath }' is not a file. " );
76+ Assertion::readable ($ this ->filePath , "Specified file ' {$ this ->filePath }' must be readable. " );
7477 }
7578
76- Assertion::file ($ file , "Specified path ' {$ file }' is not a file. " );
77- Assertion::readable ($ file , "Specified file ' {$ file }' must be readable. " );
78- Assertion::writeable ($ file , "Specified path ' {$ file }' must be writeable. " );
79-
80- $ this ->handle = fopen ($ file , 'r+ ' );
79+ $ this ->handle = fopen ($ this ->filePath , 'r+ ' );
8180 }
8281
8382 /**
0 commit comments