Skip to content

Commit

Permalink
Removing the need to supply credentials using envvars for unit tests
Browse files Browse the repository at this point in the history
Added default credentials to phpunit.xml.dist and configured a couple S3
tests to create clients specific to the test rather than rely on global state.
  • Loading branch information
mtdowling committed Jul 11, 2014
1 parent 1ffd7d8 commit dad601f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -12,7 +12,7 @@ before_script:
- composer self-update
- composer install --no-interaction --prefer-source --dev

script: AWS_ACCESS_KEY_ID=foo AWS_SECRET_ACCESS_KEY=bar vendor/bin/phpunit
script: vendor/bin/phpunit

matrix:
allow_failures:
Expand Down
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Expand Up @@ -2,6 +2,12 @@
<phpunit bootstrap="./tests/bootstrap.php"
colors="true">

<!-- Dummy values used to provide credentials. No need to change these. -->
<php>
<server name="AWS_ACCESS_KEY_ID" value="foo" />
<server name="AWS_ACCESS_KEY_ID" value="bar" />
</php>

<testsuites>
<testsuite name="Aws">
<directory>tests/Aws/Tests</directory>
Expand Down
14 changes: 10 additions & 4 deletions tests/Aws/Tests/S3/S3ClientTest.php
Expand Up @@ -81,8 +81,11 @@ public function testFactoryInitializesClient()
*/
public function testCreatesPresignedUrls()
{
/** @var $client S3Client */
$client = $this->getServiceBuilder()->get('s3', true);
$client = S3Client::factory([
'region' => 'us-east-1',
'key' => 'foo',
'secret' => 'bar'
]);
$request = $client->get('/foobar');
$original = (string) $request;
$url = $client->createPresignedUrl($request, 1342138769);
Expand All @@ -97,8 +100,11 @@ public function testCreatesPresignedUrls()
*/
public function testCreatesPresignedUrlsWithSpecialCharacters()
{
/** @var $client S3Client */
$client = $this->getServiceBuilder()->get('s3', true);
$client = S3Client::factory([
'region' => 'us-east-1',
'key' => 'foo',
'secret' => 'bar'
]);
$request = $client->get('/foobar test: abc/+%.a');
$url = $client->createPresignedUrl($request, 1342138769);
$this->assertContains('https://s3.amazonaws.com/foobar%20test%3A%20abc/%2B%25.a?AWSAccessKeyId=', $url);
Expand Down

0 comments on commit dad601f

Please sign in to comment.