-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomTest.php
More file actions
42 lines (29 loc) · 1.26 KB
/
CustomTest.php
File metadata and controls
42 lines (29 loc) · 1.26 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
<?php
declare(strict_types=1);
use DragonCode\RequestTracker\TrackerHeader;
use DragonCode\RequestTracker\TrackerRequest;
use Symfony\Component\HttpFoundation\Request;
it('sets header from callback when header is absent and casts ints to strings', function () {
$headerName = 'Some-Header';
$request = makeRequest();
$header = new TrackerHeader;
$telemetry = new TrackerRequest($request, $header);
$telemetry->custom($headerName, function (Request $req) {
expect($req)->toBeInstanceOf(Request::class);
return 1234; // will be cast to string by TelemetryRequest::set
});
expect($request->headers->get($headerName))->toBe('1234');
});
it('preserves existing header and does not call the callback when header is present', function () {
$headerName = 'Some-Header';
$request = makeRequest([$headerName => 'qwerty']);
$called = false;
$header = new TrackerHeader;
$telemetry = new TrackerRequest($request, $header);
$telemetry->custom($headerName, function () use (&$called) {
$called = true; // must remain false if existing header is used
return 'should-not-be-used';
});
expect($called)->toBeFalse()
->and($request->headers->get($headerName))->toBe('qwerty');
});