Repository navigation
Expand file tree
/
Copy pathAssert.php
More file actions
110 lines (98 loc) · 2.87 KB
/
Copy pathAssert.php
File metadata and controls
110 lines (98 loc) · 2.87 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
<?hh // strict
namespace HackPack\HackUnit;
final class Assert implements Contract\Assert {
public static function build(
Vector<Event\FailureListener> $failureListeners,
Vector<Event\SkipListener> $skipListeners,
Vector<Event\SuccessListener> $successListeners,
): this {
return new static($failureListeners, $skipListeners, $successListeners);
}
public function __construct(
private Vector<Event\FailureListener> $failureListeners,
private Vector<Event\SkipListener> $skipListeners,
private Vector<Event\SuccessListener> $successListeners,
) {}
public function bool(bool $context): Contract\Assertion\BoolAssertion {
return new Assertion\BoolAssertion(
$context,
$this->failureListeners,
$this->successListeners,
);
}
public function int(int $context): Contract\Assertion\NumericAssertion<int> {
return new Assertion\NumericAssertion(
$context,
$this->failureListeners,
$this->successListeners,
);
}
public function float(
float $context,
): Contract\Assertion\NumericAssertion<float> {
return new Assertion\NumericAssertion(
$context,
$this->failureListeners,
$this->successListeners,
);
}
public function string(string $context): Contract\Assertion\StringAssertion {
return new Assertion\StringAssertion(
$context,
$this->failureListeners,
$this->successListeners,
);
}
public function whenCalled(
(function(): void) $context,
): Contract\Assertion\CallableAssertion {
return new Assertion\CallableAssertion(
$context,
$this->failureListeners,
$this->successListeners,
);
}
public function mixed(mixed $context): Contract\Assertion\MixedAssertion {
return new Assertion\MixedAssertion(
$context,
$this->failureListeners,
$this->successListeners,
);
}
public function container<T>(
Container<T> $context,
): Contract\Assertion\ContainerAssertion<T> {
return new Assertion\ContainerAssertion(
$context,
$this->failureListeners,
$this->successListeners,
);
}
public function keyedContainer<Tkey, Tval>(
KeyedContainer<Tkey, Tval> $context,
): Contract\Assertion\KeyedContainerAssertion<Tkey, Tval> {
return new Assertion\KeyedContainerAssertion(
$context,
$this->failureListeners,
$this->successListeners,
);
}
public function skip(
string $reason,
?Util\TraceItem $traceItem = null,
): void {
if ($traceItem === null) {
$stack = Util\Trace::generate();
$traceItem = shape(
'file' => $stack[0]['file'],
'line' => $stack[0]['line'],
'function' => $stack[1]['function'],
'class' => $stack[1]['class'],
);
}
$skip = new Event\Skip($reason, $traceItem, Util\Trace::findTestMethod());
foreach ($this->skipListeners as $l) {
$l($skip);
}
}
}