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

Guzzle 5 to 6 #1

Merged
merged 2 commits into from
Sep 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@
}
],
"license": "MIT",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/adamwathan/socialnorm"
}
],
"require": {
"php": ">=5.4.0",
"guzzlehttp/guzzle": "~5.0",
"socialnorm/socialnorm": "0.1.*"
"guzzlehttp/guzzle": "^6.0",
"socialnorm/socialnorm": "^0.2"
},
"require-dev": {
"mockery/mockery": "~0.8"
"mockery/mockery": "~0.8",
"phpunit/phpunit": "^4.8"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/GitHubProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function getEmailUrl()
public function getJson($url, $headers)
{
$response = $this->httpClient->get($url, ['headers' => $headers]);
return $response->json();
return json_decode($response->getBody(), true);
}

protected function getPrimaryEmail($emails)
Expand Down
36 changes: 24 additions & 12 deletions tests/GitHubProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,38 @@
use SocialNorm\GitHub\GitHubProvider;
use SocialNorm\Request;

use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Subscriber\Mock as SubscriberMock;

class GitHubProviderTest extends TestCase
{
private function getStubbedHttpClient($responses = [])
private function getStubbedHttpClient($fixtures = [])
{
$client = new HttpClient;
$mockSubscriber = new SubscriberMock($responses);
$client->getEmitter()->attach($mockSubscriber);
return $client;
$mock = new MockHandler($this->createResponses($fixtures));
$handler = HandlerStack::create($mock);
return new HttpClient(['handler' => $handler]);
}

private function createResponses($fixtures)
{
$responses = [];
foreach ($fixtures as $fixture) {
$response = require $fixture;
$responses[] = new Response($response['status'], $response['headers'], $response['body']);
}

return $responses;
}

/** @test */
public function it_can_retrieve_a_normalized_user()
{
$client = $this->getStubbedHttpClient([
__DIR__ . '/_fixtures/github_accesstoken.txt',
__DIR__ . '/_fixtures/github_user.txt',
__DIR__ . '/_fixtures/github_email.txt',
__DIR__ . '/_fixtures/github_accesstoken.php',
__DIR__ . '/_fixtures/github_user.php',
__DIR__ . '/_fixtures/github_email.php',
]);

$provider = new GitHubProvider([
Expand All @@ -49,9 +61,9 @@ public function it_can_retrieve_a_normalized_user()
public function it_fails_to_retrieve_a_user_when_the_authorization_code_is_omitted()
{
$client = $this->getStubbedHttpClient([
__DIR__ . '/_fixtures/github_accesstoken.txt',
__DIR__ . '/_fixtures/github_user.txt',
__DIR__ . '/_fixtures/github_email.txt',
__DIR__ . '/_fixtures/github_accesstoken.php',
__DIR__ . '/_fixtures/github_user.php',
__DIR__ . '/_fixtures/github_email.php',
]);

$provider = new GitHubProvider([
Expand Down
27 changes: 27 additions & 0 deletions tests/_fixtures/github_accesstoken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

return [
'status' => 200,
'headers' => [
'Server' => 'GitHub.com',
'Date' => 'Sat, 21 Feb 2015 18:44:34 GMT',
'Content-Type' => 'application/json; charset=utf-8',
'Transfer-Encoding' => 'chunked',
'Status' => '200 OK',
'Content-Security-Policy' => 'default-src *; script-src assets-cdn.github.com collector-cdn.github.com; object-src assets-cdn.github.com; style-src \'self\' \'unsafe-inline\' \'unsafe-eval\' assets-cdn.github.com; img-src \'self\' data: assets-cdn.github.com identicons.github.com www.google-analytics.com collector.githubapp.com *.githubusercontent.com *.gravatar.com *.wp.com; media-src \'none\'; frame-src \'self\' render.githubusercontent.com gist.github.com www.youtube.com player.vimeo.com checkout.paypal.com; font-src assets-cdn.github.com; connect-src \'self\' ghconduit.com:25035 live.github.com wss://live.github.com uploads.github.com www.google-analytics.com s3.amazonaws.com',
'Cache-Control' => 'no-cache',
'Vary' => 'X-PJAX, Accept-Encoding',
'X-UA-Compatible' => 'IE=Edge,chrome=1',
'Set-Cookie' => 'logged_in=no; domain=.github.com; path=/; expires=Wed, 21-Feb-2035 18:44:34 GMT; secure; HttpOnly, _gh_sess=eyJzZXNzaW9uX2lkIjoiNDZkZDdiMTMzNDIxMjQ5OTNjZjliNmUyMzg4OTM5MWUiLCJsYXN0X3dyaXRlIjoxNDI0NTQ0Mjc0NDgzfQ%3D%3D--4ca192ff94067bcf8922b053b0758d1f580f85a6; path=/; secure; HttpOnly',
'X-Request-Id' => 'f8898bcf19b20706de5712177bdf9eeb',
'X-Runtime' => '0.010527',
'X-Rack-Cache' => 'invalidate, pass',
'X-GitHub-Request-Id' => 'AE71B20F:0FF4:159043E3:54E8D212',
'Strict-Transport-Security' => 'max-age=31536000; includeSubdomains; preload',
'X-Content-Type-Options' => 'nosniff',
'X-XSS-Protection' => '1; mode=block',
'X-Frame-Options' => 'deny',
'X-Served-By' => 'a568c03544f42dddf712bab3bfd562fd'
],
'body' => '{"access_token":"abcdefgh12345678","token_type":"bearer","scope":"user:email"}'
];
22 changes: 0 additions & 22 deletions tests/_fixtures/github_accesstoken.txt

This file was deleted.

33 changes: 33 additions & 0 deletions tests/_fixtures/github_email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

return [
'status' => 200,
'headers' => [
'Server' => 'GitHub.com',
'Date' => 'Thu, 19 Mar 2015 03:42:05 GMT',
'Content-Type' => 'application/json; charset=utf-8',
'Content-Length' => '62',
'Status' => '200 OK',
'X-RateLimit-Limit' => '5000',
'X-RateLimit-Remaining' => '4948',
'X-RateLimit-Reset' => '1426740125',
'Cache-Control' => 'private, max-age=60, s-maxage=60',
'ETag' => '"06ddc2c2d17761bc98b0e6419aed512c"',
'X-OAuth-Scopes' => 'user:email',
'X-Accepted-OAuth-Scopes' => 'user, user:email',
'X-OAuth-Client-Id' => 'b80ba34640eb08f2b3e5',
'Vary' => 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding',
'X-GitHub-Media-Type' => 'github.v3',
'X-XSS-Protection' => '1; mode=block',
'X-Frame-Options' => 'deny',
'Content-Security-Policy' => 'default-src \'none\'',
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Expose-Headers' => 'ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval',
'Access-Control-Allow-Origin' => '*',
'X-GitHub-Request-Id' => 'AE71B20F:4EF8:83D06C:550A458D',
'Strict-Transport-Security' => 'max-age=31536000; includeSubdomains; preload',
'X-Content-Type-Options' => 'nosniff',
'X-Served-By' => 'b0ef53392caa42315c6206737946d931'
],
'body' => '[{"email": "[email protected]","primary": true,"verified": true}]'
];
34 changes: 0 additions & 34 deletions tests/_fixtures/github_email.txt

This file was deleted.

34 changes: 34 additions & 0 deletions tests/_fixtures/github_user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

return [
'status' => 200,
'headers' => [
'Server' => 'GitHub.com',
'Date' => 'Sat, 21 Feb 2015 18:43:17 GMT',
'Content-Type' => 'application/json; charset=utf-8',
'Content-Length' => '1278',
'Status' => '200 OK',
'X-RateLimit-Limit' => '5000',
'X-RateLimit-Remaining' => '4961',
'X-RateLimit-Reset' => '1424546049',
'Cache-Control' => 'private, max-age=60, s-maxage=60',
'Last-Modified' => 'Sat, 21 Feb 2015 17:06:00 GMT',
'ETag' => '"7a29c845b431fa302144d2d2da66e7e3"',
'X-OAuth-Scopes' => 'user:email',
'X-Accepted-OAuth-Scopes' => '',
'X-OAuth-Client-Id' => 'b80ba34640eb08f2b3e5',
'Vary' => 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding',
'X-GitHub-Media-Type' => 'github.v3',
'X-XSS-Protection' => '1; mode=block',
'X-Frame-Options' => 'deny',
'Content-Security-Policy' => 'default-src \'none\'',
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Expose-Headers' => 'ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval',
'Access-Control-Allow-Origin' => '*',
'X-GitHub-Request-Id' => 'AE71B20F:202B:3ABE9811:54E8D1C5',
'Strict-Transport-Security' => 'max-age=31536000; includeSubdomains; preload',
'X-Content-Type-Options' => 'nosniff',
'X-Served-By' => '065b43cd9674091fec48a221b420fbb3'
],
'body' => '{"login":"adamwathan","id":4323180,"avatar_url":"https://avatars.githubusercontent.com/u/4323180?v=3","gravatar_id":"","url":"https://api.github.com/users/adamwathan","html_url":"https://github.com/adamwathan","followers_url":"https://api.github.com/users/adamwathan/followers","following_url":"https://api.github.com/users/adamwathan/following{/other_user}","gists_url":"https://api.github.com/users/adamwathan/gists{/gist_id}","starred_url":"https://api.github.com/users/adamwathan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamwathan/subscriptions","organizations_url":"https://api.github.com/users/adamwathan/orgs","repos_url":"https://api.github.com/users/adamwathan/repos","events_url":"https://api.github.com/users/adamwathan/events{/privacy}","received_events_url":"https://api.github.com/users/adamwathan/received_events","type":"User","site_admin":false,"name":"Adam Wathan","company":"Tighten Co","blog":"","location":"Ontario,Canada","email":"","hireable":false,"bio":null,"public_repos":38,"public_gists":12,"followers":54,"following":10,"created_at":"2013-05-02T15:35:48Z","updated_at":"2015-02-21T17:06:00Z"}'
];
60 changes: 0 additions & 60 deletions tests/_fixtures/github_user.txt

This file was deleted.