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 */
1115class 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}
0 commit comments