|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ShouldPHP |
|
4
|
|
|
* |
|
5
|
|
|
* @author Gabriel Jacinto <[email protected]> |
|
6
|
|
|
* @status dev |
|
7
|
|
|
* @link https://github.com/GabrielJMJ/ShouldPHP |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Gabrieljmj\Should\Report; |
|
12
|
|
|
|
|
13
|
|
|
class Report |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Name of the tested ambient |
|
17
|
|
|
* |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
private $name; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Total of assertions executed |
|
24
|
|
|
* |
|
25
|
|
|
* @var integer |
|
26
|
|
|
*/ |
|
27
|
|
|
private $total = 0; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Total of successful assertions |
|
31
|
|
|
* |
|
32
|
|
|
* @var integer |
|
33
|
|
|
*/ |
|
34
|
|
|
private $successTotal = 0; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Total of unsuccessful assertions |
|
38
|
|
|
* |
|
39
|
|
|
* @var integer |
|
40
|
|
|
*/ |
|
41
|
|
|
private $failTotal = 0; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Executed assertions details |
|
45
|
|
|
* |
|
46
|
|
|
* @var array |
|
47
|
|
|
*/ |
|
48
|
|
|
private $assertList = []; |
|
49
|
|
|
|
|
50
|
|
|
public function __construct($name) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->name = $name; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Returns the name of the tested ambient |
|
57
|
|
|
* |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getName() |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->name; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Adds an assert to assert list |
|
67
|
|
|
* |
|
68
|
|
|
* @param \Gabrieljmj\Should\Report\AssertReport $report |
|
69
|
|
|
*/ |
|
70
|
|
|
public function addAssert(AssertReport $report) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->total++; |
|
73
|
|
|
$report->getStatus() === 'success' ? $this->successTotal++ : $this->failTotal++; |
|
74
|
|
|
$this->assertList[$report->getType()][$report->getStatus()][$report->getTestedElement()][] = $report; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Returns the total of assertions executed |
|
79
|
|
|
* |
|
80
|
|
|
* @return integer |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getTotal() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->total; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Returns the total of successful assertions |
|
89
|
|
|
* |
|
90
|
|
|
* @return integer |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getSuccessTotal() |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->successTotal; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Return the total of unsuccessful assertions |
|
99
|
|
|
* |
|
100
|
|
|
* @return integer |
|
101
|
|
|
*/ |
|
102
|
|
|
public function getFailTotal() |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->failTotal; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Returns the executed assertions |
|
109
|
|
|
* Each array element is an instance of \Gabrieljmj\Should\Report\ReportAssertion |
|
110
|
|
|
* |
|
111
|
|
|
* @return array |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getAssertList() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->assertList; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Serializes the report |
|
120
|
|
|
* |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
|
|
public function serialize() |
|
124
|
|
|
{ |
|
125
|
|
|
$report = [ |
|
126
|
|
|
'total' => $this->getTotal(), |
|
127
|
|
|
'success_total' => $this->getSuccessTotal(), |
|
128
|
|
|
'fail_total' => $this->getFailTotal(), |
|
129
|
|
|
'elements' => [] |
|
130
|
|
|
]; |
|
131
|
|
|
|
|
132
|
|
|
foreach ($this->getAssertList() as $typeName => $type) { |
|
133
|
|
|
foreach ($type as $status => $elements) { |
|
134
|
|
|
foreach ($elements as $elementName => $element) { |
|
135
|
|
|
foreach ($element as $assert) { |
|
136
|
|
|
$report['elements'][$typeName][$elementName][$status][] = [ |
|
137
|
|
|
'name' => $assert->getName(), |
|
138
|
|
|
'description' => $assert->getDescription(), |
|
139
|
|
|
'fail_message' => $assert->getFailMessage(), |
|
140
|
|
|
'message' => $assert->getMessage() |
|
141
|
|
|
]; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
return serialize($report); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Unserializes a string of a report |
|
152
|
|
|
* |
|
153
|
|
|
* @param string $str |
|
154
|
|
|
*/ |
|
155
|
|
|
public function unserialize($str) |
|
|
|
|
|
|
156
|
|
|
{ |
|
157
|
|
|
return ; |
|
158
|
|
|
} |
|
159
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.