Skip to content

Commit

Permalink
added test to test if closure was called before sending request
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastiaanKloos committed Nov 7, 2023
1 parent 3728a9d commit 6472c7a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Ray.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ public function sendRequest($payloads, array $meta = []): self
], $meta);

if ($closure = static::$beforeSendRequest) {
$closure($payloads, $meta);
$closure($payloads, $allMeta);
}

foreach ($payloads as $payload) {
Expand Down
14 changes: 14 additions & 0 deletions tests/RayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1176,3 +1176,17 @@ function (InvalidArgumentException $e, $ray) {

expect($sentRequests[0]['payloads'][0]['content']['level'])->toBe(999);
});

it('can add a closure for before send and actually calls it', function () {
$this->closureCalled = false;

$this->ray::beforeSendRequest(function () {
$this->closureCalled = true;
});

$this->ray->send(function ($ray) {
$ray->text('Hello world');
});

expect($this->closureCalled)->toBeTrue();
});

0 comments on commit 6472c7a

Please sign in to comment.