Skip to content

Commit

Permalink
Keep message format keys for nicer middleware names
Browse files Browse the repository at this point in the history
  • Loading branch information
onlime committed Mar 14, 2024
1 parent 52f27ed commit 70691b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/Mixins/PendingRequestMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ public function log()
return $this;
}

$messageFormats = array_values(
config('http-client-global-logger.format')
);

$stack = $this->buildHandlerStack();

/** @var Logger $logger */
$logger = Log::channel(config('http-client-global-logger.channel'));
if (! is_null($name)) {
$logger = $logger->withName($name);
}
foreach ($messageFormats as $key => $format) {

foreach (config('http-client-global-logger.format') as $key => $format) {
// We'll use unshift instead of push, to add the middleware to the bottom of the stack, not the top
$stack->unshift(
Middleware::log($logger, new MessageFormatter($format)),
Expand Down
6 changes: 3 additions & 3 deletions tests/PendingRequestMixinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

// We need to invade the HandlerStack to access the stack property or findByName method
expect($handler)->toBeInstanceOf(HandlerStack::class)
->and(invade($handler)->findByName('http-client-global-logger-0'))->toBeInt()
->and(invade($handler)->findByName('http-client-global-logger-1'))->toBeInt()
->and(fn () => invade($handler)->findByName('http-client-global-logger-2'))
->and(invade($handler)->findByName('http-client-global-logger-request'))->toBeInt()
->and(invade($handler)->findByName('http-client-global-logger-response'))->toBeInt()
->and(fn () => invade($handler)->findByName('http-client-global-logger-0'))
->toThrow(\InvalidArgumentException::class);
});

0 comments on commit 70691b2

Please sign in to comment.