-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathExtendedResponseTest.php
More file actions
61 lines (50 loc) · 1.77 KB
/
ExtendedResponseTest.php
File metadata and controls
61 lines (50 loc) · 1.77 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
<?php
use BeyondCode\ClaudeHooks\Hooks\Response;
it('can block and send immediately', function () {
$response = new class extends Response {
public function testBlockAndSend(): void {
ob_start();
try {
$this->blockAndSend('Tool execution blocked');
} catch (SystemExit $e) {
// Expected
}
$output = ob_get_clean();
$data = json_decode($output, true);
expect($data)->toBeArray();
expect($data['decision'])->toBe('block');
expect($data['reason'])->toBe('Tool execution blocked');
}
};
$response->testBlockAndSend();
});
it('can approve and send immediately', function () {
$response = new class extends Response {
public function testApproveAndSend(): void {
ob_start();
try {
$this->approveAndSend('Tool execution approved');
} catch (SystemExit $e) {
// Expected
}
$output = ob_get_clean();
$data = json_decode($output, true);
expect($data)->toBeArray();
expect($data['decision'])->toBe('approve');
expect($data['reason'])->toBe('Tool execution approved');
}
};
$response->testApproveAndSend();
});
it('blockAndSend terminates execution', function () {
$response = new Response();
expect(function () use ($response) {
$response->blockAndSend('Blocked');
})->toThrow(SystemExit::class);
});
it('approveAndSend terminates execution', function () {
$response = new Response();
expect(function () use ($response) {
$response->approveAndSend('Approved');
})->toThrow(SystemExit::class);
});