Skip to content
Browse files

BUG tweak screenshot take logic to create directory

take screenshot logic now creates directory if provided and not existing in the filesystem
  • Loading branch information...
1 parent 955f951 commit e1654029dc9a34480e181c2df7c3415ce8b5bc32 @michalochman committed Aug 14, 2012
Showing with 15 additions and 4 deletions.
  1. +1 −1 behat.yml
  2. +14 −3 features/bootstrap/SilverStripe/Test/Behaviour/BasicContext.php
View
2 behat.yml
@@ -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:
View
17 features/bootstrap/SilverStripe/Test/Behaviour/BasicContext.php
@@ -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;
}

0 comments on commit e165402

Please sign in to comment.
Something went wrong with that request. Please try again.