Repository navigation
Expand file tree
/
Copy pathTraceTest.php
More file actions
164 lines (143 loc) · 4.49 KB
/
Copy pathTraceTest.php
File metadata and controls
164 lines (143 loc) · 4.49 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?hh // strict
namespace HackPack\HackUnit\Tests\Util;
use HackPack\HackUnit\Contract\Assert;
use HackPack\HackUnit\Util\Trace;
use HackPack\HackUnit\Util\TraceItem;
class TraceTest {
private function nonStrings(): Vector<mixed> {
return Vector {
1,
0,
-1,
true,
false,
0.1,
0.0,
-1.1,
[],
['a'],
new TraceTest(),
};
}
private function nonInts(): Vector<mixed> {
return Vector {
'a',
'longer string?',
true,
false,
0.1,
0.0,
-1.1,
[],
['a'],
new TraceTest(),
};
}
<<Test>>
public function missingParamsResultsInNull(Assert $assert): void {
$raw = [];
$items = Trace::convert([$raw]);
$assert->int($items->count())->eq(1);
$item = $items->at(0);
$assert->mixed($item['line'])->isNull();
$assert->mixed($item['function'])->isNull();
$assert->mixed($item['class'])->isNull();
$assert->mixed($item['file'])->isNull();
}
<<Test>>
public function lineMustBeInteger(Assert $assert): void {
foreach ($this->nonInts() as $mixed) {
$item = Trace::convert([['line' => $mixed]])->at(0);
$assert->mixed($item['line'])->isNull();
}
foreach ([-1, 0, 1, 3] as $int) {
$item = Trace::convert([['line' => $int]])->at(0);
$assert->mixed($item['line'])->identicalTo($int);
}
}
<<Test>>
public function functionMustBeString(Assert $assert): void {
foreach ($this->nonStrings() as $mixed) {
$item = Trace::convert([['function' => $mixed]])->at(0);
$assert->mixed($item['function'])->isNull();
}
foreach (['', '0', '1e10', 'normal string'] as $string) {
$item = Trace::convert([['function' => $string]])->at(0);
$assert->mixed($item['function'])->identicalTo($string);
}
}
<<Test>>
public function classMustBeString(Assert $assert): void {
foreach ($this->nonStrings() as $mixed) {
$item = Trace::convert([['class' => $mixed]])->at(0);
$assert->mixed($item['class'])->isNull();
}
foreach (['', '0', '1e10', 'normal string'] as $string) {
$item = Trace::convert([['class' => $string]])->at(0);
$assert->mixed($item['class'])->identicalTo($string);
}
}
<<Test>>
public function fileMustBeString(Assert $assert): void {
foreach ($this->nonStrings() as $mixed) {
$item = Trace::convert([['file' => $mixed]])->at(0);
$assert->mixed($item['file'])->isNull();
}
foreach (['', '0', '1e10', 'normal string'] as $string) {
$item = Trace::convert([['file' => $string]])->at(0);
$assert->mixed($item['file'])->identicalTo($string);
}
}
<<Test>>
public function assertionCallSearchFailsWhenSearchingWithoutAssertion(
Assert $assert,
): void {
$item = Trace::findAssertionCall();
$assert->mixed($item['line'])->isNull();
$assert->mixed($item['function'])->isNull();
$assert->mixed($item['class'])->isNull();
$assert->mixed($item['file'])->isNull();
}
<<Test>>
public function assertionCallSearchSucceedsWhenSearchingWithAssertion(
Assert $assert,
): void {
$mockAssert = new \HackPack\HackUnit\Tests\Doubles\Util\Assertion();
$items = Vector {};
$line = __LINE__ + 5;
$mockAssert->run(
() ==> {
$items->add(Trace::findAssertionCall());
},
);
$assert->int($items->count())->eq(1);
$item = $items->at(0);
$assert->mixed($item['line'])->isInt();
$assert->mixed($item['function'])->isString();
$assert->mixed($item['class'])->isString();
$assert->mixed($item['file'])->isString();
$assert->int((int) $item['line'])->eq($line);
$assert->string((string) $item['function'])->is(__FUNCTION__);
$assert->string((string) $item['class'])->is(__CLASS__);
$assert->string((string) $item['file'])->is(__FILE__);
}
private function levelOne(): TraceItem {
return $this->levelTwo();
}
private function levelTwo(): TraceItem {
return Trace::findTestMethod();
}
<<Test>>
public function findTestMethod(Assert $assert): void {
$line = __LINE__ + 1;
$item = $this->levelOne();
$assert->mixed($item['line'])->isInt();
$assert->mixed($item['function'])->isString();
$assert->mixed($item['class'])->isString();
$assert->mixed($item['file'])->isString();
$assert->int((int) $item['line'])->eq($line);
$assert->string((string) $item['function'])->is(__FUNCTION__);
$assert->string((string) $item['class'])->is(__CLASS__);
$assert->string((string) $item['file'])->is(__FILE__);
}
}