-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathPhpSpec.php
More file actions
125 lines (107 loc) · 3.74 KB
/
Copy pathPhpSpec.php
File metadata and controls
125 lines (107 loc) · 3.74 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace PHPCensor\Plugin;
use PHPCensor\Builder;
use PHPCensor\Model\Build;
use PHPCensor\Plugin;
use SimpleXMLElement;
/**
* PHP Spec Plugin - Allows PHP Spec testing.
*
* @package PHP Censor
* @subpackage Application
*
* @author Dan Cryer <dan@block8.co.uk>
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class PhpSpec extends Plugin
{
/**
* @return string
*/
public static function pluginName()
{
return 'php_spec';
}
public function __construct(Builder $builder, Build $build, array $options = [])
{
parent::__construct($builder, $build, $options);
$this->executable = $this->findBinary(['phpspec', 'phpspec.php', 'phpspec.phar']);
}
/**
* Runs PHP Spec tests.
*/
public function execute()
{
$phpspec = $this->executable;
$success = $this->builder->executeCommand(Builder::PHP_CLI_TAG . ' ' . $phpspec . ' --format=junit --no-code-generation run');
$output = $this->builder->getLastOutput();
/*
* process xml output
*
* <testsuites time=FLOAT tests=INT failures=INT errors=INT>
* <testsuite name=STRING time=FLOAT tests=INT failures=INT errors=INT skipped=INT>
* <testcase name=STRING time=FLOAT classname=STRING status=STRING/>
* </testsuite>
* </testsuites
*/
$xml = new SimpleXMLElement($output);
$attr = $xml->attributes();
$data = [
'time' => (float)$attr['time'],
'tests' => (int)$attr['tests'],
'failures' => (int)$attr['failures'],
'errors' => (int)$attr['errors'],
// now all the tests
'suites' => [],
];
/**
* @var SimpleXMLElement $group
*/
foreach ($xml->xpath('testsuite') as $group) {
$attr = $group->attributes();
$suite = [
'name' => (string)$attr['name'],
'time' => (float)$attr['time'],
'tests' => (int)$attr['tests'],
'failures' => (int)$attr['failures'],
'errors' => (int)$attr['errors'],
'skipped' => (int)$attr['skipped'],
// now the cases
'cases' => [],
];
/**
* @var SimpleXMLElement $child
*/
foreach ($group->xpath('testcase') as $child) {
$attr = $child->attributes();
$case = [
'name' => (string)$attr['name'],
'classname' => (string)$attr['classname'],
'time' => (float)$attr['time'],
'status' => (string)$attr['status'],
];
if ('failed' === $case['status']) {
$error = [];
/*
* ok, sad, we had an error
*
* there should be one - foreach makes this easier
*/
foreach ($child->xpath('failure') as $failure) {
$attr = $failure->attributes();
$error['type'] = (string)$attr['type'];
$error['message'] = (string)$attr['message'];
}
foreach ($child->xpath('system-err') as $systemError) {
$error['raw'] = (string)$systemError;
}
$case['error'] = $error;
}
$suite['cases'][] = $case;
}
$data['suites'][] = $suite;
}
$this->build->storeMeta((self::pluginName() . '-data'), $data);
return $success;
}
}