From 276d78529ee4b4611f77198cc02e9c72ba05f799 Mon Sep 17 00:00:00 2001 From: Art4 Date: Tue, 1 Nov 2016 22:26:30 +0100 Subject: [PATCH] Release 0.5 --- CHANGELOG.md | 15 +++++++++------ composer.json | 2 +- src/Client.php | 6 +++--- tests/unit/ClientTest.php | 34 ++++++++++++++++++++-------------- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1846593..b090571 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +## [0.5] - 2016-11-01 + ### Added - Implementation for OAuth2 Authorization Code Grant was added. @@ -18,7 +20,7 @@ All notable changes to this project will be documented in this file. ### Changed -- [Youthweb API 0.6](https://github.com/youthweb/youthweb-api/releases/tag/0.6) Support. +- [Youthweb-API 0.6](https://github.com/youthweb/youthweb-api/releases/tag/0.6) Support. - **Breaking:** All classes are set to `final` and implement interfaces. All protected methods are now private. If you had extend some classes, implement the interface instead. - **Breaking:** `$data` in `Client::getUnauthorized()`, `Client::getUnauthorized()` and `Client::postUnauthorized()` must be an array. It cannot be `null` anymore. - Switch LICENSE from GPLv2 to GPLv3. @@ -39,7 +41,7 @@ All notable changes to this project will be documented in this file. ### Changed -- [Youthweb API 0.5](https://github.com/youthweb/youthweb-api/releases/tag/0.5) Support +- [Youthweb-API 0.5](https://github.com/youthweb/youthweb-api/releases/tag/0.5) Support ### Added @@ -50,7 +52,7 @@ All notable changes to this project will be documented in this file. ### Changed -- [Youthweb API 0.3](https://github.com/youthweb/youthweb-api/releases/tag/0.3) Support +- [Youthweb-API 0.3](https://github.com/youthweb/youthweb-api/releases/tag/0.3) Support - **Breaking:** API Resources return the data as `Art4\JsonApiClient\Document` object instead of `stdClass` ### Removed @@ -62,7 +64,7 @@ All notable changes to this project will be documented in this file. ### Added -- [Youthweb API 0.2](https://github.com/youthweb/youthweb-api/releases/tag/0.2) Support +- [Youthweb-API 0.2](https://github.com/youthweb/youthweb-api/releases/tag/0.2) Support - phpunit tests - Travis-CI Support - this CHANGELOG.md @@ -71,10 +73,11 @@ All notable changes to this project will be documented in this file. ### Added -- First workable client for Youthweb API [Version 0.1](https://github.com/youthweb/youthweb-api/releases/tag/0.1) +- First workable client for Youthweb-API [Version 0.1](https://github.com/youthweb/youthweb-api/releases/tag/0.1) - Http client based on [guzzlehttp/guzzle ~5.0](https://github.com/guzzle/guzzle) -[Unreleased]: https://github.com/youthweb/php-youthweb-api/compare/0.4...HEAD +[Unreleased]: https://github.com/youthweb/php-youthweb-api/compare/0.5...HEAD +[0.5]: https://github.com/youthweb/php-youthweb-api/compare/0.4...0.5 [0.4]: https://github.com/youthweb/php-youthweb-api/compare/0.3...0.4 [0.3]: https://github.com/youthweb/php-youthweb-api/compare/0.2...0.3 [0.2]: https://github.com/youthweb/php-youthweb-api/compare/0.1...0.2 diff --git a/composer.json b/composer.json index 0eb5b62..e5e7086 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ { "name": "Artur Weigandt", "email": "art4@youthweb.net", - "homepage": "http://wlabs.de" + "homepage": "https://wlabs.de" } ], "require": { diff --git a/src/Client.php b/src/Client.php index 86f59e7..fe575fd 100644 --- a/src/Client.php +++ b/src/Client.php @@ -380,7 +380,7 @@ public function getState() */ public function get($path, array $data = []) { - $data['headers']['Authorization'] = 'Bearer ' . $this->getBearerToken(); + $data['headers']['Authorization'] = 'Bearer ' . $this->getAccessToken(); $request = $this->createRequest('GET', $this->getUrl() . $path, $data); @@ -589,9 +589,9 @@ private function getOauth2Provider() * * @throws UnauthorizedException contains the url to get an authorization code * - * @return string The Bearer token incl. type e.g. "Bearer jcx45..." + * @return string The Bearer token, e.g. "jcx45..." */ - private function getBearerToken() + private function getAccessToken() { if ( ! $this->isAuthorized() ) { diff --git a/tests/unit/ClientTest.php b/tests/unit/ClientTest.php index 29f9a76..8013ffb 100644 --- a/tests/unit/ClientTest.php +++ b/tests/unit/ClientTest.php @@ -729,7 +729,6 @@ public function testHandleClientExceptionWithResponseException() $request_factory = $this->createMock('Youthweb\Api\RequestFactoryInterface'); $request = $this->createMock('Psr\Http\Message\RequestInterface'); $response = $this->createMock('Psr\Http\Message\ResponseInterface'); - $exception = $this->createMock('GuzzleHttp\Exception\ClientException'); $http_client = $this->createMock('Youthweb\Api\HttpClientInterface'); $auth_resource = $this->createMock('Youthweb\Api\Resource\AuthInterface'); $resource_factory = $this->createMock('Youthweb\Api\ResourceFactoryInterface'); @@ -742,7 +741,7 @@ public function testHandleClientExceptionWithResponseException() ->method('isHit') ->willReturn(false); - $cache_provider->expects($this->exactly(2)) + $cache_provider->expects($this->exactly(3)) ->method('getItem') ->will($this->returnValueMap([ ['php_youthweb_api.access_token', $cache_item_access], @@ -756,9 +755,11 @@ public function testHandleClientExceptionWithResponseException() ->method('getBody') ->willReturn($body); - $exception->expects($this->once()) - ->method('getResponse') - ->willReturn($response); + $response->expects($this->once()) + ->method('getStatusCode') + ->willReturn(401); + + $exception = new \GuzzleHttp\Exception\ClientException('The server responses with an unknown error.', $request, $response); $http_client->expects($this->once()) ->method('send') @@ -787,7 +788,8 @@ public function testHandleClientExceptionWithResponseException() $this->setExpectedException( 'Exception', - 'Unauthorized' + 'Unauthorized', + 401 ); $client->get('foobar'); @@ -800,7 +802,6 @@ public function testHandleClientExceptionWithDetailResponseException() { $body = $this->createMock('Psr\Http\Message\StreamInterface'); $response = $this->createMock('Psr\Http\Message\ResponseInterface'); - $exception = $this->createMock('GuzzleHttp\Exception\ClientException'); $cache_provider = $this->createMock('Psr\Cache\CacheItemPoolInterface'); $cache_item_access = $this->createMock('Psr\Cache\CacheItemInterface'); $request_factory = $this->createMock('Youthweb\Api\RequestFactoryInterface'); @@ -817,15 +818,15 @@ public function testHandleClientExceptionWithDetailResponseException() ->method('getBody') ->willReturn($body); - $exception->expects($this->once()) - ->method('getResponse') - ->willReturn($response); + $response->expects($this->once()) + ->method('getStatusCode') + ->willReturn(401); $cache_item_access->expects($this->exactly(2)) ->method('isHit') ->willReturn(false); - $cache_provider->expects($this->exactly(2)) + $cache_provider->expects($this->exactly(3)) ->method('getItem') ->will($this->returnValueMap([ ['php_youthweb_api.access_token', $cache_item_access], @@ -835,6 +836,8 @@ public function testHandleClientExceptionWithDetailResponseException() ->method('createRequest') ->willReturn($request); + $exception = new \GuzzleHttp\Exception\ClientException('error message', $request, $response); + $http_client->expects($this->once()) ->method('send') ->will($this->throwException($exception)); @@ -862,7 +865,8 @@ public function testHandleClientExceptionWithDetailResponseException() $this->setExpectedException( 'Exception', - 'Detailed error message' + 'Detailed error message', + 401 ); $client->get('foobar'); @@ -873,11 +877,12 @@ public function testHandleClientExceptionWithDetailResponseException() */ public function testHandleClientExceptionWithException() { - $exception = $this->createMock('\Exception'); $http_client = $this->createMock('Youthweb\Api\HttpClientInterface'); $request_factory = $this->createMock('Youthweb\Api\RequestFactoryInterface'); $request = $this->createMock('Psr\Http\Message\RequestInterface'); + $exception = new \Exception('error message', 0); + $http_client->expects($this->once()) ->method('send') ->will($this->throwException($exception)); @@ -896,7 +901,8 @@ public function testHandleClientExceptionWithException() $this->setExpectedException( 'Exception', - 'The server responses with an unknown error.' + 'The server responses with an unknown error.', + 0 ); $client->getUnauthorized('foobar');