/
Assertion.php
110 lines (93 loc) · 2.1 KB
/
Assertion.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
105
106
107
108
109
110
<?php
namespace Jamm\Tester;
class Assertion
{
protected $expected_result;
protected $actual_result;
protected $commentary;
protected $name;
protected $successful = true;
protected $debug_line;
protected $debug_file;
protected $debug_method;
protected $debug_trace_level = 4;
public function __construct($name = '')
{
$this->parseDebugInfo();
if (empty($name)) {
$name = $this->debug_method;
}
$this->name = $name;
}
public function getActualResult()
{
return $this->actual_result;
}
public function setActualResult($actual_result)
{
$this->actual_result = $actual_result;
}
public function addCommentary($commentary)
{
if (!is_scalar($commentary)) {
$commentary = print_r($commentary, 1);
}
if (!empty($this->commentary)) {
$this->commentary .= PHP_EOL;
}
$this->commentary .= $commentary;
return $this;
}
public function getCommentary()
{
return $this->commentary;
}
public function getExpectedResult()
{
return $this->expected_result;
}
public function setExpectedResult($expected_result)
{
$this->expected_result = $expected_result;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
public function getDebugFile()
{
return $this->debug_file;
}
public function getDebugLine()
{
return $this->debug_line;
}
public function getDebugMethod()
{
return $this->debug_method;
}
public function Assert($successful = true)
{
$this->successful = $successful;
}
public function isSuccessful()
{
return $this->successful;
}
public function setDebugTraceLevel($debug_trace_level)
{
$this->debug_trace_level = $debug_trace_level;
}
private function parseDebugInfo()
{
$level = $this->debug_trace_level;
$debug_info = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
$this->debug_line = $debug_info[$level]['line'];
$this->debug_method = $debug_info[$level]['function'];
$this->debug_file = $debug_info[$level]['file'];
}
}