Skip to content

Commit ec0071e

Browse files
committed
Added ability to disable service account
1 parent eba9cb2 commit ec0071e

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

src/Client.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public function __construct(array $config)
4141
$this->client->setDeveloperKey(array_get($config, 'developer_key', ''));
4242

4343
// auth for service account
44-
$this->auth();
44+
if (array_get($config, 'service.enable', false)) {
45+
$this->auth();
46+
}
4547
}
4648

4749
/**

src/config/config.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@
4040
| Google service account
4141
|----------------------------------------------------------------------------
4242
|
43-
| Set the information below to use assert credentials
44-
| Leave blank to use app engine or compute engine.
43+
| Enable and set the information below to use assert credentials
44+
| Enable and leave blank to use app engine or compute engine.
4545
|
4646
*/
4747
'service' => [
48+
/*
49+
| Enable service account auth or not.
50+
*/
51+
'enable' => false,
52+
4853
/*
4954
5055
*/

tests/ClientTest.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ public function tearDown()
1515
public function testClientGetter()
1616
{
1717
$client = Mockery::mock('PulkitJalan\Google\Client', [[]])->makePartial();
18+
1819
$this->assertInstanceOf('Google_Client', $client->getClient());
1920
}
2021

2122
public function testServiceMake()
2223
{
2324
$client = Mockery::mock('PulkitJalan\Google\Client', [[]])->makePartial();
25+
2426
$this->assertInstanceOf('Google_Service_Storage', $client->make('storage'));
2527
}
2628

@@ -39,13 +41,21 @@ public function testMagicMethodException()
3941

4042
$this->setExpectedException('BadMethodCallException');
4143

42-
$client->getAuth2();
44+
$client->getAuthTest();
45+
}
46+
47+
public function testDefaultAuth()
48+
{
49+
$client = new \PulkitJalan\Google\Client([]);
50+
51+
$this->assertInstanceOf('Google_Auth_OAuth2', $client->getAuth());
4352
}
4453

4554
public function testAssertCredentials()
4655
{
4756
$client = new \PulkitJalan\Google\Client([
4857
'service' => [
58+
'enable' => true,
4959
'account' => 'name',
5060
'scopes' => ['scope'],
5161
'key' => __DIR__.'/data/cert.p12',
@@ -58,7 +68,12 @@ public function testAssertCredentials()
5868
public function testAppEngineCredentials()
5969
{
6070
$_SERVER['SERVER_SOFTWARE'] = 'Google App Engine';
61-
$client = new \PulkitJalan\Google\Client([]);
71+
72+
$client = new \PulkitJalan\Google\Client([
73+
'service' => [
74+
'enable' => true,
75+
],
76+
]);
6277

6378
$this->assertInstanceOf('Google_Auth_AppIdentity', $client->getAuth());
6479

@@ -67,7 +82,11 @@ public function testAppEngineCredentials()
6782

6883
public function testComputeEngineCredentials()
6984
{
70-
$client = new \PulkitJalan\Google\Client([]);
85+
$client = new \PulkitJalan\Google\Client([
86+
'service' => [
87+
'enable' => true,
88+
],
89+
]);
7190

7291
$this->assertInstanceOf('Google_Auth_ComputeEngine', $client->getAuth());
7392
}

0 commit comments

Comments
 (0)