Skip to content

Commit e1e3e91

Browse files
Merge pull request GoogleCloudPlatform#10 from SurferJeffAtGoogle/travisSquash
Store the application credential's raw json in a base64-encoded
2 parents 01e5b15 + c2d4f95 commit e1e3e91

File tree

7 files changed

+57
-6
lines changed

7 files changed

+57
-6
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33
*.iml
44
composer.phar
55
vendor/
6-
credentials.tar.gz
7-
credentials.tar
8-
cloud-samples-tests-php-808469e61d8a.json
6+
credentials.*

.travis.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ php:
1919
- hhvm
2020
- nightly
2121

22+
env:
23+
globals:
24+
- GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/credentials.json
25+
2226
before_install:
23-
# Decrypt the credentials we added to the repo using the key we added with the Travis command line tool
24-
- openssl aes-256-cbc -K $encrypted_a66730e1b199_key -iv $encrypted_a66730e1b199_iv -in credentials.tar.gz.enc -out credentials.tar.gz -d
25-
- tar -xzf credentials.tar.gz
27+
- php dump_credentials.php
2628

2729
script:
2830
- cd bigquery/api

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ accept your pull requests.
3232
(https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the
3333
recommended coding standards for this organization.
3434
1. Ensure that your code has an appropriate set of unit tests which all pass.
35+
Set up [Travis](./TRAVIS.md) to run the unit tests on your fork.
3536
1. Submit a pull request.

TRAVIS.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Running Tests on Travis
2+
3+
[Travis](https://travis-ci.org/) automatically runs tests whenever a github
4+
repo changes. To have Travis automatically run tests on your forked copy
5+
of this repo:
6+
7+
1. Fork this repo on [GitHub](https://github.com/).
8+
2. Visit the
9+
[Google Developers Console](https://console.developers.google.com/) and
10+
choose an existing project or create a new project.
11+
3. Under `APIs & auth`, choose Credentials.
12+
4. Click `Add credentials`, and then click `Service account`.
13+
5. Under `Key type`, choose `JSON`, and then click `Create`. A json credential
14+
file will be downloaded to your computer.
15+
6. Visit [Travis](https://travis-ci.org/profile ) and turn on Travis for your
16+
new forked repo.
17+
7. Go back to the [Travis](https://travis-ci.org/) home page, click on your
18+
repo, then click on `Settings`.
19+
8. Under Environment Variables, set GOOGLE_CLOUD_PROJECT to the project id
20+
for the project you created or chose in step 2.
21+
9. Base-64 encode the json file you downloaded in step 5. On unix machines,
22+
this can be done with a command like
23+
`base64 -w 0 < my-test-bf4af540ca4c.json`.
24+
10. Under Environment Variables, set GOOGLE_CREDENTIALS_BASE64 to the
25+
base64-encoded json from step 9. **Be sure te leave `Display value in build
26+
log` switched OFF.**
27+

bigquery/api/test.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,20 @@
1616
*/
1717
class MainTest extends PHPUnit_Framework_TestCase
1818
{
19+
protected static $hasCredentials;
20+
21+
public static function setUpBeforeClass()
22+
{
23+
$path = getenv('GOOGLE_APPLICATION_CREDENTIALS');
24+
self::$hasCredentials = $path && file_exists($path) &&
25+
filesize($path) > 0;
26+
}
27+
1928
public function test()
2029
{
30+
if (!self::$hasCredentials) {
31+
$this->markTestSkipped('No application credentials were found.');
32+
}
2133
// Invoke main.php.
2234
global $argc, $argv;
2335
$argv[1] = getenv('GOOGLE_CLOUD_PROJECT');

credentials.tar.gz.enc

-1.67 KB
Binary file not shown.

dump_credentials.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Dumps the contents of the environment variable GOOGLE_CREDENTIALS_BASE64 to
4+
* a file.
5+
*
6+
* To setup Travis to run on your fork, read TRAVIS.md.
7+
*/
8+
file_put_contents(
9+
getenv('GOOGLE_APPLICATION_CREDENTIALS'),
10+
base64_decode(getenv('GOOGLE_CREDENTIALS_BASE64'))
11+
);

0 commit comments

Comments
 (0)