Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions Core/src/ClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ private function detectProjectId(array $config)
'projectId' => null,
'projectIdRequired' => false,
'hasEmulator' => false,
'preferNumericProjectId' => false,
'suppressKeyFileNotice' => false
'preferNumericProjectId' => false
];

if ($config['projectId']) {
Expand All @@ -202,23 +201,6 @@ private function detectProjectId(array $config)
if (isset($config['keyFile']['project_id'])) {
return $config['keyFile']['project_id'];
}

if ($config['suppressKeyFileNotice'] !== true) {
$serviceAccountUri = 'https://cloud.google.com/iam/docs/' .
'creating-managing-service-account-keys#creating_service_account_keys';

trigger_error(
sprintf(
'A keyfile was given, but it does not contain a project ' .
'ID. This can indicate an old and obsolete keyfile, ' .
'in which case you should create a new one. To suppress ' .
'this message, set `suppressKeyFileNotice` to `true` in your client configuration. ' .
'To learn more about generating new keys, see this URL: %s',
$serviceAccountUri
),
E_USER_NOTICE
);
}
}

if (getenv('GOOGLE_CLOUD_PROJECT')) {
Expand Down
27 changes: 0 additions & 27 deletions Core/tests/Unit/ClientTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,33 +358,6 @@ public function testDetectProjectIdEmulator()

$this->assertEquals($projectId, $res);
}

public function testDetectProjectIdWithKeyfileMissingProjectId()
{
set_error_handler(static function (int $errno, string $errstr): never {
throw new Exception($errstr, $errno);
}, E_USER_NOTICE);
$this->expectException(Exception::class);
$this->expectExceptionMessage('A keyfile was given');

$trait = TestHelpers::impl(ClientTrait::class);

$res = $trait->call('detectProjectId', [[
'keyFile' => []
]]);
}

public function testDetectProjectIdWithKeyfileMissingProjectIdSuppressNotice()
{
$trait = TestHelpers::impl(ClientTraitStubOnGceReturnsFalse::class);

$res = $trait->call('detectProjectId', [[
'keyFile' => [],
'suppressKeyFileNotice' => true
]]);

$this->assertTrue(true);
}
}

//@codingStandardsIgnoreStart
Expand Down
Loading