Skip to content

Commit 20b0cf2

Browse files
committed
Addressed Travis testing issues
1 parent b497de5 commit 20b0cf2

File tree

7 files changed

+18
-19
lines changed

7 files changed

+18
-19
lines changed

auth/auth.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
// Create auth-cloud-implicit Command.
3030
$application->add((new Command('auth-cloud-implicit'))
31+
->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID')
3132
->setDescription('Authenticate to a cloud client library using a service account implicitly.')
3233
->setHelp(<<
3334
The %command.name% command authenticates to a cloud client library
@@ -38,13 +39,14 @@
3839
EOF
3940
)
4041
->setCode(function ($input, $output) {
41-
auth_cloud_implicit();
42+
auth_cloud_implicit($input->getArgument('projectId'));
4243
})
4344
);
4445

4546
// Create auth-cloud-explicit Command.
4647
$application->add((new Command('auth-cloud-explicit'))
4748
->addArgument('serviceAccountPath', InputArgument::REQUIRED, 'Path to your service account.')
49+
->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID')
4850
->setDescription('Authenticate to a cloud client library using a service account explicitly.')
4951
->setHelp(<<
5052
The %command.name% command authenticates to a cloud client library
@@ -55,7 +57,7 @@
5557
EOF
5658
)
5759
->setCode(function ($input, $output) {
58-
auth_cloud_explicit($input->getArgument('serviceAccountPath'));
60+
auth_cloud_explicit($input->getArgument('projectId'), $input->getArgument('serviceAccountPath'));
5961
})
6062
);
6163

auth/index.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,3 @@
3838
auth_api_explicit_app_engine(getenv('GCLOUD_PROJECT'));
3939
}
4040
print('');
41-
42-
43-

auth/src/auth_api_explicit_app_engine.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
# [START auth_api_explicit_app_engine]
2424
namespace Google\Cloud\Samples\Auth;
25+
2526
use Google\Auth\Credentials\AppIdentityCredentials;
2627
use Google\Auth\Middleware\AuthTokenMiddleware;
2728
use GuzzleHttp\Client;

auth/src/auth_api_explicit_compute_engine.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
# [START auth_api_explicit_compute_engine]
2424
namespace Google\Cloud\Samples\Auth;
25+
2526
use Google\Auth\Credentials\GCECredentials;
2627
use Google\Auth\Middleware\AuthTokenMiddleware;
2728
use GuzzleHttp\Client;

auth/src/auth_cloud_explicit.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
// Imports the Google Cloud Storage client library.
2727
use Google\Cloud\Storage\StorageClient;
2828

29-
function auth_cloud_explicit($serviceAccountPath)
29+
function auth_cloud_explicit($projectId, $serviceAccountPath)
3030
{
3131
# Explicitly use service account credentials by specifying the private key
3232
# file.
3333
$config = [
3434
'keyFilePath' => $serviceAccountPath,
35+
'projectId' => $projectId,
3536
];
3637
$storage = new StorageClient($config);
3738

auth/src/auth_cloud_implicit.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@
2626
// Imports the Google Cloud Storage client library.
2727
use Google\Cloud\Storage\StorageClient;
2828

29-
function auth_cloud_implicit()
29+
function auth_cloud_implicit($projectId)
3030
{
31+
$config = [
32+
'projectId' => $projectId,
33+
];
34+
3135
# If you don't specify credentials when constructing the client, the
3236
# client library will look for credentials in the environment.
33-
$storage = new StorageClient();
37+
$storage = new StorageClient($config);
3438

3539
# Make an authenticated API request (listing storage buckets)
3640
foreach ($storage->buckets() as $bucket) {

auth/test/authTest.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ public function setUp()
3232
$this->markTestSkipped('Set the GOOGLE_APPLICATION_CREDENTIALS ' .
3333
'environment variable');
3434
}
35-
$this->bucketName = getenv('GCS_BUCKET_NAME');
35+
$this->bucketName = getenv('GOOGLE_STORAGE_BUCKET');
3636
$this->projectId = getenv('GCLOUD_PROJECT');
3737
}
3838

3939
public function testAuthCloudImplicitCommand()
4040
{
41-
$output = $this->runCommand('auth-cloud-implicit');
41+
$output = $this->runCommand('auth-cloud-implicit', null, $this->projectId);
4242
$this->assertContains($this->bucketName, $output);
4343
}
4444

4545
public function testAuthCloudExplicitCommand()
4646
{
4747
$serviceAccountPath = getenv('GOOGLE_APPLICATION_CREDENTIALS');
48-
$output = $this->runCommand('auth-cloud-explicit', $serviceAccountPath);
48+
$output = $this->runCommand('auth-cloud-explicit', $serviceAccountPath, $this->projectId);
4949
$this->assertContains($this->bucketName, $output);
5050
}
5151

@@ -97,7 +97,7 @@ private function runCommand($commandName, $serviceAccountPath=null, $projectId=n
9797
$commandTester = new CommandTester($command);
9898

9999
ob_start();
100-
if ($serviceAccountPath and $projectId) {
100+
if ($serviceAccountPath) {
101101
try {
102102
$commandTester->execute(
103103
[
@@ -111,13 +111,6 @@ private function runCommand($commandName, $serviceAccountPath=null, $projectId=n
111111
$application->renderException($e, $commandTester->getOutput());
112112
return $commandTester->getDisplay();
113113
}
114-
} else if ($serviceAccountPath) {
115-
$commandTester->execute(
116-
[
117-
'serviceAccountPath'=> $serviceAccountPath
118-
],
119-
['interactive' => false]
120-
);
121114
} else if ($projectId) {
122115
try {
123116
$commandTester->execute(

0 commit comments

Comments
 (0)