-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathVisualCeptionReporter.php
More file actions
executable file
·78 lines (63 loc) · 2.09 KB
/
Copy pathVisualCeptionReporter.php
File metadata and controls
executable file
·78 lines (63 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
*
*/
namespace Codeception\Module;
class VisualCeptionReporter extends \Codeception\Module
{
private $failed = array();
private $logFile;
private $templateVars = array();
private $templateFile;
private $referenceImageDir;
public function __construct($config)
{
$result = parent::__construct($config);
$this->init();
return $result;
}
private function init()
{
$this->debug("Initializing VisualCeptionReport");
if (array_key_exists('logFile', $this->config)) {
$this->logFile = $this->config["logFile"];
}else{
$this->logFile = \Codeception\Configuration::logDir() . 'vcresult.html';
}
if (array_key_exists('templateVars', $this->config)) {
$this->templateVars = $this->config["templateVars"];
}
if (array_key_exists('templateFile', $this->config)) {
$this->templateFile = $this->config["templateFile"];
} else {
$this->templateFile = __DIR__ . "/report/template.php";
}
}
public function _beforeSuite()
{
if (!$this->hasModule("VisualCeption")) {
throw new \Exception("VisualCeptionReporter uses VisualCeption. Please be sure that this module is activated.");
}
$this->referenceImageDir = $this->getModule("VisualCeption")->getReferenceImageDir();
$this->debug( "VisualCeptionReporter: templateFile = " . $this->templateFile );
}
public function _afterSuite()
{
$failedTests = $this->failed;
$vars = $this->templateVars;
$referenceImageDir = $this->referenceImageDir;
$i = 0;
ob_start();
include_once $this->templateFile;
$reportContent = ob_get_contents();
ob_clean();
$this->debug("Trying to store file (".$this->logFile.")");
file_put_contents($this->logFile, $reportContent);
}
public function _failed(\Codeception\TestCase $test, $fail)
{
if ($fail instanceof ImageDeviationException) {
$this->failed[] = $fail;
}
}
}