Skip to content

Commit c6718ea

Browse files
authored
Merge pull request #34 from buresmi7/fixFileNameFormat
Fix file name format
2 parents 6da4ac7 + 8d00532 commit c6718ea

6 files changed

Lines changed: 42 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.buildpath
22
.project
33
.settings/
4+
/vendor

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ before_script:
1111
- composer install
1212
- php vendor/bin/codecept build -c test/integration/
1313

14-
script: php vendor/bin/codecept run -c test/integration/
14+
script:
15+
- php vendor/bin/codecept run -c test/integration/
16+
- vendor/bin/phpunit test/unit/

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"ext-imagick": "*"
99
},
1010
"require-dev": {
11-
"codeception/codeception": "^2.2.0"
11+
"codeception/codeception": "^2.2.0",
12+
"phpunit/phpunit": "^5.7.0"
1213
},
1314
"autoload": {
1415
"classmap": ["module/"]

module/Utils.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Codeception\Module\VisualCeption;
4+
5+
class Utils
6+
{
7+
public function getTestFileName($signature, $identifier)
8+
{
9+
return str_replace([':', '\\'], '.', $signature) . '.' . $identifier . '.png';
10+
}
11+
}

module/VisualCeption.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Codeception\Module as CodeceptionModule;
55
use Codeception\Test\Descriptor;
66
use RemoteWebDriver;
7+
use Codeception\Module\VisualCeption\Utils;
78

89
/**
910
* Class VisualCeption
@@ -50,13 +51,20 @@ class VisualCeption extends CodeceptionModule
5051
*/
5152
private $webDriverModule = null;
5253

54+
/**
55+
* @var Utils
56+
*/
57+
private $utils;
58+
5359
private $failed = array();
5460
private $logFile;
5561
private $templateVars = array();
5662
private $templateFile;
5763

5864
public function _initialize()
5965
{
66+
$this->utils = new Utils();
67+
6068
$this->maximumDeviation = $this->config["maximumDeviation"];
6169
$this->saveCurrentImageIfFailure = (boolean)$this->config["saveCurrentImageIfFailure"];
6270
$this->referenceImageDir = (file_exists($this->config["referenceImageDir"]) ? "" : codecept_data_dir()) . $this->config["referenceImageDir"];
@@ -312,7 +320,7 @@ private function getCoordinates($elementId)
312320
private function getScreenshotName($identifier)
313321
{
314322
$signature = $this->test->getSignature();
315-
return str_replace(':', '_', $signature). '.' . $identifier . '.png';
323+
return $this->utils->getTestFileName($signature, $identifier);
316324
}
317325

318326
/**

test/unit/UtilsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Codeception\Module\VisualCeption\Test\Unit;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Codeception\Module\VisualCeption\Utils;
7+
8+
class UtilsTest extends TestCase
9+
{
10+
public function testGetTestFileName()
11+
{
12+
$utils = new Utils();
13+
$this->assertEquals('Acceptance.Work.Test.test.screenshot.png', $utils->getTestFileName('Acceptance\Work\Test:test', 'screenshot'));
14+
$this->assertEquals('Test.test.screenshot.png', $utils->getTestFileName('Test:test', 'screenshot'));
15+
}
16+
}

0 commit comments

Comments
 (0)