Skip to content

Commit a5f70c8

Browse files
ssankoAlexander Horvath
and
Alexander Horvath
authored
check for directory existence when storing console log or storing source, if it does not exist create it (#1143)
Co-authored-by: Alexander Horvath <[email protected]>
1 parent 0a88da6 commit a5f70c8

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/Browser.php

+18-4
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,16 @@ public function storeConsoleLog($name)
484484
$console = $this->driver->manage()->getLog('browser');
485485

486486
if (! empty($console)) {
487+
$filePath = sprintf('%s/%s.log', rtrim(static::$storeConsoleLogAt, '/'), $name);
488+
489+
$directoryPath = dirname($filePath);
490+
491+
if (! is_dir($directoryPath)) {
492+
mkdir($directoryPath, 0777, true);
493+
}
494+
487495
file_put_contents(
488-
sprintf('%s/%s.log', rtrim(static::$storeConsoleLogAt, '/'), $name), json_encode($console, JSON_PRETTY_PRINT)
496+
$filePath, json_encode($console, JSON_PRETTY_PRINT)
489497
);
490498
}
491499
}
@@ -504,9 +512,15 @@ public function storeSource($name)
504512
$source = $this->driver->getPageSource();
505513

506514
if (! empty($source)) {
507-
file_put_contents(
508-
sprintf('%s/%s.txt', rtrim(static::$storeSourceAt, '/'), $name), $source
509-
);
515+
$filePath = sprintf('%s/%s.txt', rtrim(static::$storeSourceAt, '/'), $name);
516+
517+
$directoryPath = dirname($filePath);
518+
519+
if (! is_dir($directoryPath)) {
520+
mkdir($directoryPath, 0777, true);
521+
}
522+
523+
file_put_contents($filePath, $source);
510524
}
511525

512526
return $this;

0 commit comments

Comments
 (0)