diff --git a/src/ClientOptionsTrait.php b/src/ClientOptionsTrait.php index 63cd99984..3228e03dd 100644 --- a/src/ClientOptionsTrait.php +++ b/src/ClientOptionsTrait.php @@ -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' ); diff --git a/tests/Tests/Unit/ClientOptionsTraitTest.php b/tests/Tests/Unit/ClientOptionsTraitTest.php index b41d462a5..23ba7eff3 100644 --- a/tests/Tests/Unit/ClientOptionsTraitTest.php +++ b/tests/Tests/Unit/ClientOptionsTraitTest.php @@ -196,7 +196,9 @@ public function buildClientOptionsProvider() 'rest' => [ 'logger' => null, ], - 'grpc-fallback' => [], + 'grpc-fallback' => [ + 'logger' => null, + ], ], 'credentials' => null, 'credentialsConfig' => [], @@ -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'); }