-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCasperJs.php
104 lines (80 loc) · 2.39 KB
/
CasperJs.php
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace Demorose\PHPCI\Plugin;
use PHPCI\Plugin;
use PHPCI\Builder;
use PHPCI\Model\Build;
use Demorose\PHPCI\Plugin\Util\XUnitParser;
/**
* CasperJs - Allows CasperJS testing.
* @author Emmanuel LEVEQUE <[email protected]>
*/
class CasperJs implements Plugin
{
/**
* @var \PHPCI\Builder
*/
protected $phpci;
/**
* @var \PHPCI\Model\Build
*/
protected $build;
protected $x_unit_file_path = '/tmp/casperOutput.xml';
protected $tests_path = 'tests/test.js';
protected $arguments = '';
/**
* Standard Constructor
*/
public function __construct(Builder $phpci, Build $build, array $options = array())
{
$this->phpci = $phpci;
$this->build = $build;
$this->buildArgs($options);
}
/**
* Run CasperJS tests.
* @return bool
*/
public function execute()
{
$this->phpci->logExecOutput(false);
$casperJs = $this->phpci->findBinary('casperjs');
if (!$casperJs) {
$this->phpci->logFailure(Lang::get('could_not_find', 'casperjs'));
return false;
}
$curdir = getcwd();
chdir($this->phpci->buildPath);
$cmd = $casperJs . " test $this->tests_path --xunit=$this->x_unit_file_path $this->arguments";
$success = $this->phpci->executeCommand($cmd);
chdir($curdir);
$xUnitString = file_get_contents($this->x_unit_file_path);
try {
$xUnitParser = new XUnitParser($xUnitString);
$output = $xUnitParser->parse();
$failures = $xUnitParser->getTotalFailures();
} catch (\Exception $ex) {
$this->phpci->logFailure($xUnitParser);
throw $ex;
}
$this->build->storeMeta('casperJs-errors', $failures);
$this->build->storeMeta('casperJs-data', $output);
$this->phpci->logExecOutput(true);
return $success;
}
/**
* Build an args string for PHPCS Fixer.
* @param $options
*/
public function buildArgs($options)
{
if (!empty($options['tests_path'])) {
$this->tests_path = $options['tests_path'];
}
if (!empty($options['x_unit_file_path'])) {
$this->x_unit_file_path = $options['x_unit_file_path'];
}
if (!empty($options['arguments'])) {
$this->arguments= $options['arguments'];
}
}
}