Skip to content

Commit

Permalink
Update max lenght to be in a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Hectorhammett committed Dec 11, 2024
1 parent 6aaf4de commit d611f8e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/HttpHandler/Guzzle6HttpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __invoke(RequestInterface $request, array $options = [])
$response = $this->client->send($request, $options);

if ($this->logger) {
$this->responseLog($response, $requestEvent);
$this->responseLog($response, $requestEvent);
}

return $response;
Expand Down Expand Up @@ -120,6 +120,11 @@ public function requestLog(RequestInterface $request, array $options): RpcLogEve
return $requestEvent;
}

/**
* @internal
* @param RequestInterface $request
* @param array<mixed> $options
*/
public function responseLog(ResponseInterface $response, RpcLogEvent $requestEvent): void

Check failure on line 128 in src/HttpHandler/Guzzle6HttpHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis / PHPStan Static Analysis

PHPDoc tag @param references unknown parameter: $options

Check failure on line 128 in src/HttpHandler/Guzzle6HttpHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis / PHPStan Static Analysis

PHPDoc tag @param references unknown parameter: $request
{
$responseEvent = new RpcLogEvent($requestEvent->milliseconds);
Expand Down
6 changes: 4 additions & 2 deletions src/Logging/LoggingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ private function getJwtToken(array $headers): null|array
*/
private function truncatePayload(null|string $payload): null|string
{
if (is_null($payload) || strlen($payload) <= 500) {
$maxLength = 500;

if (is_null($payload) || strlen($payload) <= $maxLength) {
return $payload;
}

return substr($payload, 0, 500) . '...';
return substr($payload, 0, $maxLength) . '...';
}
}
5 changes: 5 additions & 0 deletions tests/ApplicationDefaultCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,11 @@ public function testGetDefaultLoggerReturnsNullIfNotEnvVar()
$logger = ApplicationDefaultCredentials::getDefaultLogger();

$this->assertNull($logger);

putenv($this::SDK_DEBUG_ENV_VAR . '=');
$logger = ApplicationDefaultCredentials::getDefaultLogger();

$this->assertNull($logger);
}

public function testGetDefaultLoggerRaiseAWarningIfMisconfiguredAndReturnsNull()
Expand Down
6 changes: 2 additions & 4 deletions tests/HttpHandler/Guzzle7HttpHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ public function testLoggerDoesNotGetsCalledIfLoggerIsNotPassed()
$request = new Request('GET', 'https://domain.tld');
$options = ['key' => 'value'];

/**
* @var LoggerInterface $mockLogger
* @var ClientInterface $mockClient
*/
$handler = new Guzzle7HttpHandler($this->client->reveal());
$handler->async($request, $options)->wait();

$this->expectOutputString('');
}
}
16 changes: 14 additions & 2 deletions tests/Logging/LoggingTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@

class LoggingTraitTest extends BaseTest
{
private MockClassWithLogger $loggerContainer;
private $loggerContainer;

public function setUp(): void
{
$this->loggerContainer = new MockClassWithLogger();
$this->loggerContainer = new class() {
use LoggingTrait {
logRequest as public;
logResponse as public;
}

private LoggerInterface $logger;

public function __construct()
{
$this->logger = new StdOutLogger();
}
};
}

public function testLogRequest()
Expand Down

0 comments on commit d611f8e

Please sign in to comment.