Skip to content

Commit

Permalink
Fix unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Hectorhammett committed Sep 26, 2024
1 parent 3a2a798 commit e8526d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ClientOptionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private function buildClientOptions(array $options)
$options['logger'] = $options['logger'] ?? ApplicationDefaultCredentials::getDefaultLogger();
}

if ($options['logger'] !== false && !$options['logger'] instanceof LoggerInterface) {
if ($options['logger']!== null && $options['logger'] !== false && !$options['logger'] instanceof LoggerInterface) {
throw new ValidationException(
'The "logger" option in the options array should be PSR-3 LoggerInterface compatible'
);
Expand Down
13 changes: 8 additions & 5 deletions tests/Tests/Unit/ClientOptionsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ public function buildClientOptionsProvider()
'rest' => [
'logger' => null,
],
'grpc-fallback' => [],
'grpc-fallback' => [
'logger' => null,
],
],
'credentials' => null,
'credentialsConfig' => [],
Expand Down Expand Up @@ -555,17 +557,18 @@ public function testBuildClientOptionsTwice()
$this->assertEquals($options, $options2);
}

public function testLoggerIsNullWhenNullIsPassed()
public function testLoggerIsNullWhenFalseIsPassed()
{
putenv('GOOGLE_SDK_DEBUG_LOGGING=true');

$client = new StubClientOptionsClient();
$optionsArray = [
'logger' => null,
'logger' => false,
];
$options = $client->buildClientOptions($optionsArray);
$this->assertNull($options['transportConfig']['rest']['logger']);
$this->assertNull($options['transportConfig']['grpc']['logger']);
$this->assertFalse($options['transportConfig']['rest']['logger']);
$this->assertFalse($options['transportConfig']['grpc']['logger']);
$this->assertFalse($options['transportConfig']['grpc-fallback']['logger']);

putenv('GOOGLE_SDK_DEBUG_LOGGING');
}
Expand Down

0 comments on commit e8526d6

Please sign in to comment.