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
|
|
|
use Gabrieljmj\Should\Assert\AssertInterface; |
14
|
|
|
use Gabrieljmj\Should\Report\AssertType; |
15
|
|
|
|
16
|
|
|
class AssertReport |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Assert type (class, property, method etc) |
20
|
|
|
* Use constants from \Gabrieljmj\Should\Report\AssertType |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $type; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Assert |
28
|
|
|
* |
29
|
|
|
* @var \Gabrieljmj\Should\Assert\AssertInterface |
30
|
|
|
*/ |
31
|
|
|
private $assert; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* AssertReport constructor |
35
|
|
|
* |
36
|
|
|
* @param string $type |
37
|
|
|
* @param \Gabrieljmj\Should\Assert\AssertInterface $assert |
38
|
|
|
*/ |
39
|
|
|
public function __construct($type, AssertInterface $assert) |
40
|
|
|
{ |
41
|
|
|
$this->type = $type; |
42
|
|
|
$this->assert = $assert; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Assert type (class, property, method etc) |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
public function getType() |
51
|
|
|
{ |
52
|
|
|
return $this->type; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Returns null if status is true |
57
|
|
|
* |
58
|
|
|
* @return string|null |
59
|
|
|
*/ |
60
|
|
|
public function getFailMessage() |
61
|
|
|
{ |
62
|
|
|
return $this->assert->getFailMessage(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns assert name |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function getName() |
71
|
|
|
{ |
72
|
|
|
$nameEx = explode('\\', get_class($this->assert)); |
73
|
|
|
return end($nameEx); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Returns the tested element |
78
|
|
|
* |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
public function getTestedElement() |
82
|
|
|
{ |
83
|
|
|
return $this->assert->getTestedElement(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns the validation status |
88
|
|
|
* |
89
|
|
|
* @return boolean |
90
|
|
|
*/ |
91
|
|
|
public function getStatus() |
92
|
|
|
{ |
93
|
|
|
return $this->assert->execute() ? 'success' : 'fail'; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Returns the assert description |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function getDescription() |
102
|
|
|
{ |
103
|
|
|
return $this->assert->getDescription(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Returns the custom message in case of failure |
108
|
|
|
* |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
public function getMessage() |
112
|
|
|
{ |
113
|
|
|
return $this->assert->getMessage(); |
114
|
|
|
} |
115
|
|
|
} |