Skip to content

Commit

Permalink
feat: add logger to client constructor config (#2606)
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanphp authored Jul 10, 2024
1 parent 71579b7 commit 1f47133
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public function __construct(array $config = [])
'prompt' => '',
'openid.realm' => '',
'include_granted_scopes' => null,
'logger' => null,
'login_hint' => '',
'request_visible_actions' => '',
'access_type' => 'online',
Expand Down Expand Up @@ -242,6 +243,11 @@ public function __construct(array $config = [])
$this->setCache($this->config['cache']);
unset($this->config['cache']);
}

if (!is_null($this->config['logger'])) {
$this->setLogger($this->config['logger']);
unset($this->config['logger']);
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/Google/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ public function testDefaultLoggerAppEngine()
$this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler);
}

public function testLoggerFromConstructor()
{
$logger1 = new \Monolog\Logger('unit-test');
$client = new Client(['logger' => $logger1]);
$logger2 = $client->getLogger();
$this->assertInstanceOf('Monolog\Logger', $logger2);
$this->assertEquals('unit-test', $logger2->getName());
$this->assertSame($logger1, $logger2);
}

public function testSettersGetters()
{
$client = new Client();
Expand All @@ -279,6 +289,7 @@ public function testSettersGetters()

$client->setRedirectUri('localhost');
$client->setConfig('application_name', 'me');
$client->setLogger(new \Monolog\Logger('test'));

$cache = $this->prophesize(CacheItemPoolInterface::class);
$client->setCache($cache->reveal());
Expand Down

0 comments on commit 1f47133

Please sign in to comment.