Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined variable error in HttpRequestWrapper #20

Merged

Conversation

mcrumm
Copy link
Contributor

@mcrumm mcrumm commented Mar 9, 2016

Fixes #19

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 9, 2016
@mcrumm
Copy link
Contributor Author

mcrumm commented Mar 9, 2016

Oops... I missed the part where my application default credentials were getting loaded in my local environment.

@dwsupplee Any suggestions for providing some credentials that could work for this test? Or would it be better to create mocks for token generation flow?

I'll admit, the test is a little heavy-handed for the amount of code that changed, but I didn't want to submit anything without some form of test to back it.

@dwsupplee
Copy link
Contributor

Thanks for the contribution. It looks like there were some issues with the build:

Google\Gcloud\Tests\HttpRequestWrapperTest::testSignRequestCanCheckTheExistingCredentialsExpiry
DomainException: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information

If you've got the time to address this, that would be fantastic. If not, my upcoming PR should address this for you in a few days.

@mcrumm
Copy link
Contributor Author

mcrumm commented Mar 9, 2016

Sure! Let me see what I can do.

@dwsupplee
Copy link
Contributor

@mcrumm

Apologies for the timing of my response earlier, I didn't see your question before I had posted.

You should be able to provide a mock keyFile and mock response from the authHttpHandler, something along the lines of the following:

use GuzzleHttp\Psr7\Response;

$keyFile = json_encode([
    'type' => 'authorized_user',
    'client_id' => '[email protected]',
    'client_secret' => 'example',
    'refresh_token' => 'abc'
]);

$authHttpHandler = function($request) {
    return new Response(
        200,
        [],
        json_encode(['access_token' => 'abc'])
    );
};

$wrapper = new HttpRequestWrapper(
    $keyFile,
    null,
    [],
    null,
    $authHttpHandler
);

Let me know if this helps! :)

public function testSignRequestCanCheckTheExistingCredentialsExpiry()
{
if (class_exists('GuzzleHttp\\Message\\Request')) {
$request = new Guzzle5Request('GET', '/foo');

This comment was marked as spam.

@mcrumm mcrumm force-pushed the http_wrapper_existing_credentials branch from ec04043 to 426ca6c Compare March 9, 2016 20:27
@mcrumm
Copy link
Contributor Author

mcrumm commented Mar 9, 2016

@dwsupplee OK, I've got a much simpler approach to the test, and the build is passing again.

@mcrumm
Copy link
Contributor Author

mcrumm commented Mar 9, 2016

@dwsupplee Sorry for all the nonsense. This is "passing", but that's because I broke the test :-(

I'm fixing it up, now.

@dwsupplee
Copy link
Contributor

@mcrumm No nonsense at all! I think it's awesome you're taking the time to help and contribute.

What do you think about using the mocks as I outlined above? It should help us up the actual line coverage.

@mcrumm mcrumm force-pushed the http_wrapper_existing_credentials branch from 426ca6c to 8ccf4da Compare March 9, 2016 20:53
@mcrumm
Copy link
Contributor Author

mcrumm commented Mar 9, 2016

@dwsupplee I didn't see your comment until after I had started down the path of using Reflection to open up the private HttpRequestWrapper::$credentials variable in order to skip the OAuth2 flow, but still hit the expiry check.

Let me know if you're satisfied with the structure of this test. If not, I can take another swing at it using the approach you mentioned.

@dwsupplee
Copy link
Contributor

👍 We can go ahead and run with this for now. My upcoming commit has a few changes to this class and will be providing more coverage, when that happens I may make some changes to match the structure of the rest of the tests.

dwsupplee added a commit that referenced this pull request Mar 9, 2016
Fix undefined variable error in HttpRequestWrapper
@dwsupplee dwsupplee merged commit 9431369 into googleapis:master Mar 9, 2016
@mcrumm
Copy link
Contributor Author

mcrumm commented Mar 9, 2016

Sounds good! Thanks for the merge.

Any chance we'll see a (pre-)release on packagist after your next refactor?

@dwsupplee
Copy link
Contributor

Yes, we're planning to get a release on packagist and docs published by the end of the month.

@mcrumm
Copy link
Contributor Author

mcrumm commented Mar 9, 2016

👍 Looking forward to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants