Skip to content
This repository has been archived by the owner on Aug 13, 2018. It is now read-only.

Commit

Permalink
BUG tweak screenshot take logic to create directory
Browse files Browse the repository at this point in the history
take screenshot logic now creates directory if provided and not existing in the filesystem
  • Loading branch information
michalochman committed Aug 14, 2012
1 parent 955f951 commit e165402
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion behat.yml
Expand Up @@ -4,7 +4,7 @@ default:
parameters:
admin_url: /admin/
login_url: /Security/login
screenshot_path: features/screenshots/
screenshot_path: %behat.paths.features%/screenshots/
extensions:
features/extensions/SilverStripeExtension/init.php:
# Behat\SilverStripeExtension\Extension:
Expand Down
17 changes: 14 additions & 3 deletions features/bootstrap/SilverStripe/Test/Behaviour/BasicContext.php
Expand Up @@ -192,18 +192,29 @@ public function takeScreenshot(StepEvent $event) {
$parent = $event->getLogicalParent();
$feature = $parent->getFeature();
$step = $event->getStep();
$screenshot_path = null;

if (isset($this->context['screenshot_path'])) {
$screenshot_path = realpath($this->context['screenshot_path']);
} else {
if (!$screenshot_path) {
\Filesystem::makeFolder($this->context['screenshot_path']);
$screenshot_path = realpath($this->context['screenshot_path']);
}
}
if (!$screenshot_path) {
$screenshot_path = realpath(sys_get_temp_dir());
}

if (!is_dir($screenshot_path)) {
if (!file_exists($screenshot_path)) {
file_put_contents('php://stderr', sprintf('"%s" is not valid directory and failed to create it' . PHP_EOL, $this->context['screenshot_path']));
return;
}

if (file_exists($screenshot_path) && !is_dir($screenshot_path)) {
file_put_contents('php://stderr', sprintf('"%s" is not valid directory' . PHP_EOL, $this->context['screenshot_path']));
return;
}
if (!is_writable($screenshot_path)) {
if (file_exists($screenshot_path) && !is_writable($screenshot_path)) {
file_put_contents('php://stderr', sprintf('"%s" directory is not writable' . PHP_EOL, $screenshot_path));
return;
}
Expand Down

0 comments on commit e165402

Please sign in to comment.