Skip to content

Commit

Permalink
Fix undefined variable error in HttpRequestWrapper
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
mcrumm committed Mar 9, 2016
1 parent 1fefffd commit 8ccf4da
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/HttpRequestWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function send(RequestInterface $request, array $options = [])
*/
public function signRequest(RequestInterface $request)
{
if (!$this->credentials || $credentials['expiry'] < time()) {
if (!$this->credentials || $this->credentials['expiry'] < time()) {
$this->credentials = $this->fetchCredentials();
}

Expand Down
50 changes: 50 additions & 0 deletions tests/HttpRequestWrapperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* Copyright 2015 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Gcloud\Tests;

use Google\Gcloud\HttpRequestWrapper;
use Prophecy\Argument;
use Psr\Http\Message\RequestInterface;

class HttpRequestWrapperTest extends \PHPUnit_Framework_TestCase
{
public function testSignRequestCanCheckTheExistingCredentialsExpiry()
{
$request = $this->getMock(RequestInterface::class);
$request->method('getUri')->willReturn('/');
$request->method('getHeaders')->willReturn([]);

$wrapper = new HttpRequestWrapper();
$refl = new \ReflectionClass($wrapper);

$token = 'some_generated_token';
$credentials = $refl->getProperty('credentials');
$credentials->setAccessible(true);
$credentials->setValue($wrapper, [
'expiry' => strtotime('+300 seconds'),
'access_token' => $token
]);

$signedRequest = $wrapper->signRequest($request);

$header = $signedRequest->getHeader('Authorization')[0];

$this->assertEquals("Bearer $token", $header);
}
}

0 comments on commit 8ccf4da

Please sign in to comment.