1+ <?php
2+ /**
3+ * Created by PhpStorm.
4+ * User: langn
5+ * Date: 02.10.14
6+ * Time: 14:21
7+ *
8+ * /citools/tools/common/php/5.5.9/bin/php codecept.phar
9+ *
10+ * @todo config logfile
11+ *
12+ */
13+
14+ namespace Codeception \Module ;
15+
16+ class VisualCeptionReporter extends \Codeception \Module
17+ {
18+ private $ failed = array ();
19+ private $ logFile ;
20+ private $ templateVars = array ();
21+ private $ templateFile ;
22+
23+ private $ referenceImageDir ;
24+
25+ public function __construct ($ config )
26+ {
27+ $ result = parent ::__construct ($ config );
28+ $ this ->init ();
29+ return $ result ;
30+ }
31+
32+ private function init ()
33+ {
34+ $ this ->logFile = \Codeception \Configuration::logDir () . 'vcresult.html ' ;
35+
36+ if (array_key_exists ('templateVars ' , $ this ->config )) {
37+ $ this ->templateVars = $ this ->config ["templateVars " ];
38+ }
39+
40+ if (array_key_exists ('templateFile ' , $ this ->config )) {
41+ $ this ->templateFile = $ this ->config ["templateFile " ];
42+ } else {
43+ $ this ->templateFile = __DIR__ . "/report/template.php " ;
44+ }
45+
46+
47+ }
48+
49+ public function _beforeSuite ()
50+ {
51+ if (!$ this ->hasModule ("VisualCeption " )) {
52+ throw new \Exception ("VisualCeptionReporter uses VisualCeption. Please be sure that this module is activated. " );
53+ }
54+
55+ $ this ->referenceImageDir = $ this ->getModule ("VisualCeption " )->getReferenceImageDir ();
56+ }
57+
58+ public function _afterSuite ()
59+ {
60+ $ failedTests = $ this ->failed ;
61+ $ vars = $ this ->templateVars ;
62+ $ referenceImageDir = $ this ->referenceImageDir ;
63+ $ i = 0 ;
64+
65+ ob_start ();
66+ include_once $ this ->templateFile ;
67+ $ reportContent = ob_get_contents ();
68+ ob_clean ();
69+
70+ file_put_contents ($ this ->logFile , $ reportContent );
71+ }
72+
73+ public function _failed (\Codeception \TestCase $ test , $ fail )
74+ {
75+ if ($ fail instanceof ImageDeviationException) {
76+ $ this ->failed [] = $ fail ;
77+ }
78+ }
79+ }
0 commit comments