Skip to content

Commit 28cbbb9

Browse files
committed
Merge pull request #18 from phmLabs/master
Moved standard reference image dir to data dir
2 parents 96abe62 + 9a70095 commit 28cbbb9

File tree

11 files changed

+32
-49
lines changed

11 files changed

+32
-49
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.buildpath
2+
.project
3+
.settings/

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ php:
77
before_script:
88
- printf "\n" | pecl install imagick
99
- wget http://selenium.googlecode.com/files/selenium-server-standalone-2.35.0.jar
10-
- java -jar selenium-server-standalone-2.35.0.jar -port 4444 &
10+
- java -jar selenium-server-standalone-2.35.0.jar -port 4444 >/dev/null 2>&1 &
1111
- cd test/integration/
12-
12+
- mkdir tests/_log
1313

14-
script: php -d include_path="." codecept.phar run
14+
15+
script: php codecept.phar run -d

module/VisualCeption.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
* @copyright Copyright (c) 2014 G+J Digital Products GmbH
88
* @license MIT license, http://www.opensource.org/licenses/mit-license.php
99
* @package Codeception\Module
10+
*
11+
* @author Nils Langner <langner.nils@guj.de>
12+
* @author Torsten Franz
13+
* @author Sebastian Neubert
1014
*/
1115
class VisualCeption extends \Codeception\Module
1216
{
@@ -53,11 +57,12 @@ private function init ()
5357
if (array_key_exists('referenceImageDir', $this->config)) {
5458
$this->referenceImageDir = $this->config["referenceImageDir"];
5559
} else {
56-
throw new \RuntimeException("Reference image dir was not set, but is mandatory.");
60+
$this->referenceImageDir = \Codeception\Configuration::dataDir() . 'VisualCeption/';
5761
}
5862

5963
if (! is_dir($this->referenceImageDir)) {
60-
mkdir($this->referenceImageDir, 0666);
64+
$this->debug("Creating directory: $this->referenceImageDir");
65+
mkdir($this->referenceImageDir, 0777, true);
6166
}
6267
}
6368

@@ -112,7 +117,13 @@ private function getScreenshotPath ($identifier)
112117
{
113118
$debugDir = \Codeception\Configuration::logDir() . 'debug/tmp/';
114119
if (! is_dir($debugDir)) {
115-
mkdir($debugDir, 0666);
120+
$created = mkdir($debugDir, 0777, true);
121+
if( $created ) {
122+
$this->debug("Creating directory: $debugDir");
123+
}else{
124+
throw new \RuntimeException("Unable to create temporary screenshot dir ($debugDir)");
125+
}
126+
116127
}
117128
return $debugDir . $this->getScreenshotName($identifier);
118129
}
@@ -160,7 +171,7 @@ private function createScreenshot ($identifier, array $coords)
160171
* and their element ID
161172
*
162173
* @param string $identifier identifies your test object
163-
* @param null $elementID DOM ID of the element, which should be screenshotted
174+
* @param string $elementID DOM ID of the element, which should be screenshotted
164175
*/
165176
public function compareScreenshot ($identifier, $elementID = null)
166177
{
@@ -171,8 +182,6 @@ public function compareScreenshot ($identifier, $elementID = null)
171182

172183
unlink($this->getScreenshotPath($identifier));
173184

174-
$this->debug($compareResult);
175-
176185
$deviation = round($compareResult[1] * 100, 2);
177186

178187
if ($deviation > $this->maximumDeviation) {
@@ -207,6 +216,7 @@ private function compare ($identifier)
207216
$expectedImagePath = $this->getExpectedScreenshotPath($identifier);
208217

209218
if (! file_exists($expectedImagePath)) {
219+
$this->debug("Copying image (from $currentImagePath to $expectedImagePath");
210220
copy($currentImagePath, $expectedImagePath);
211221
return array (null, 0);
212222
} else {
@@ -229,8 +239,6 @@ private function compareImages ($image1, $image2)
229239
$result = $imagick1->compareImages($imagick2, \Imagick::METRIC_MEANSQUAREERROR);
230240
$result[0]->setImageFormat("png");
231241

232-
$this->debug($result);
233-
234242
return $result;
235243
}
236244
}

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ modules:
4242
enabled: [WebDriver, VisualCeption]
4343

4444
VisualCeption:
45-
referenceImageDir: /home/codeception/referenceImages/ # Path to the reference folder
45+
referenceImageDir: /home/codeception/referenceImages/ # Path to the reference folder (optional, standard is
46+
# <datadir>/VisualCeption/)
4647
maximumDeviation: 5 # deviation in percent
4748
```
4849
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
22
// This is global bootstrap for autoloading
33

4+
sleep(5);
5+
46
include_once __DIR__."/../../../module/VisualCeption.php";

test/integration/tests/_data/dump.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.
Binary file not shown.

test/integration/tests/_log/acceptance-2014-03-24

Lines changed: 0 additions & 34 deletions
This file was deleted.
Binary file not shown.

test/integration/tests/acceptance.suite.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ modules:
2323
capabilities:
2424
webStorageEnabled: true
2525
VisualCeption:
26-
maximumDeviation: 0
27-
referenceImageDir: /tmp/deviation/
26+
maximumDeviation: 0

0 commit comments

Comments
 (0)