diff --git a/CHANGELOG.md b/CHANGELOG.md index 58e02c5..fa2e219 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,15 +2,25 @@ All notable changes to `youtrack-rest-php` will be documented in this file. +## [6.1.0] - 2018-06-30 + +### Added + +- ([#40](https://github.com/cybercog/youtrack-rest-php/pull/40)) Multipart requests support for attachments uploads + +### Changed + +- ([#41](https://github.com/cybercog/youtrack-rest-php/pull/41)) Add missing `array` type to `$options` argument of `buildOptions` method of `Cog\YouTrack\Rest\Client\YouTrackClient` + ## [6.0.2] - 2017-01-10 -## Changed +### Changed - `Cog\YouTrack\Rest\Client\YouTrackClient` endpoint prefix is relative now ([#39](https://github.com/cybercog/youtrack-rest-php/pull/39)) ## [6.0.0] - 2017-11-20 -## Changed +### Changed - `Cog\YouTrack\Rest\Authorizer\CookieAuthorizer` stopped to delegate client header manipulation to `Authenticator` ([#32](https://github.com/cybercog/youtrack-rest-php/pull/37)) - `token` method added to `Cog\Contracts\YouTrack\Rest\Authenticator\Authenticator` contract @@ -18,13 +28,13 @@ All notable changes to `youtrack-rest-php` will be documented in this file. - `Cog\Contracts\YouTrack\Rest\Client\Exceptions\HttpClientException` extends `RuntimeException` instead of `Exception` - `Cog\Contracts\YouTrack\Rest\Authorizer\Exceptions\InvalidTokenException` renamed to `InvalidAuthorizationToken` -## Removed +### Removed - Dropped `putHeader` method from `Cog\Contracts\YouTrack\Rest\Client\Client` contract ## [5.0.0] - 2017-09-13 -## Changed +### Changed - Exceptions moved to `Cog\Contracts\YouTrack` namespace ([#34](https://github.com/cybercog/youtrack-rest-php/pull/34)). @@ -86,6 +96,7 @@ All notable changes to `youtrack-rest-php` will be documented in this file. - Initial release. +[6.1.0]: https://github.com/cybercog/youtrack-rest-php/compare/6.0.2...6.1.0 [6.0.2]: https://github.com/cybercog/youtrack-rest-php/compare/6.0.1...6.0.2 [6.0.0]: https://github.com/cybercog/youtrack-rest-php/compare/5.0.0...6.0.0 [5.0.0]: https://github.com/cybercog/youtrack-rest-php/compare/4.0.0...5.0.0 @@ -93,4 +104,4 @@ All notable changes to `youtrack-rest-php` will be documented in this file. [3.2.0]: https://github.com/cybercog/youtrack-rest-php/compare/3.1.1...3.2.0 [3.1.0]: https://github.com/cybercog/youtrack-rest-php/compare/3.0.0...3.1.0 [3.0.0]: https://github.com/cybercog/youtrack-rest-php/compare/2.0.1...3.0.0 -[2.0.1]: https://github.com/cybercog/youtrack-rest-php/compare/1.0.0...2.0.1 \ No newline at end of file +[2.0.1]: https://github.com/cybercog/youtrack-rest-php/compare/1.0.0...2.0.1 diff --git a/LICENSE b/LICENSE index 561aa76..f72d2f8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017, Anton Komarev +Copyright (c) 2018, Anton Komarev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 425c659..0119f81 100644 --- a/README.md +++ b/README.md @@ -113,8 +113,8 @@ If you discover any security related issues, please email open@cybercog.su inste ## Contributors -| ![@a-komarev](https://avatars.githubusercontent.com/u/1849174?s=110)
Anton Komarev
| ![@adam187](https://avatars.githubusercontent.com/u/156628?s=110)
Adam Misiorny
| -| :---: | :---: | +| ![@a-komarev](https://avatars.githubusercontent.com/u/1849174?s=110)
Anton Komarev
| ![@adam187](https://avatars.githubusercontent.com/u/156628?s=110)
Adam Misiorny
|
dmkdev
| +| :---: | :---: | :---: | [PHP YouTrack REST contributors list](../../contributors) diff --git a/contracts/Client/Client.php b/contracts/Client/Client.php index 988aca6..bd757cc 100644 --- a/contracts/Client/Client.php +++ b/contracts/Client/Client.php @@ -25,7 +25,7 @@ interface Client /** * Version of PHP YouTrack REST client. */ - const VERSION = '6.0.0'; + const VERSION = '6.1.0'; /** * Create and send an HTTP request. diff --git a/src/Client/YouTrackClient.php b/src/Client/YouTrackClient.php index f445e75..06f3178 100644 --- a/src/Client/YouTrackClient.php +++ b/src/Client/YouTrackClient.php @@ -218,27 +218,29 @@ protected function buildUri(string $uri): string * @param array $options * @return array */ - protected function buildOptions(array $params = [], $options = []): array + protected function buildOptions(array $params = [], array $options = []): array { $defaultOptions = [ 'form_params' => $params, 'headers' => $this->buildHeaders(), ]; - if (!isset($options['multipart']) && isset($options['form_params'])) { - $options['form_params'] = array_merge($params, $options['form_params']); - } - if (isset($options['multipart'])) { unset($defaultOptions['form_params']); foreach ($params as $key => $value) { - $options['multipart'][] = ['name' => $key, 'data' => $value]; + $options['multipart'][] = [ + 'name' => $key, + 'data' => $value, + ]; } + } elseif (isset($options['form_params'])) { + $options['form_params'] = array_merge($params, $options['form_params']); } if (isset($options['headers'])) { $options['headers'] = array_merge($this->buildHeaders(), $options['headers']); } + return array_merge($defaultOptions, $options); } diff --git a/tests/FeatureTestCase.php b/tests/FeatureTestCase.php index 52e4570..ce11ba4 100644 --- a/tests/FeatureTestCase.php +++ b/tests/FeatureTestCase.php @@ -13,7 +13,11 @@ namespace Cog\YouTrack\Rest\Tests; +use Cog\YouTrack\Rest\Authorizer\TokenAuthorizer; +use Cog\YouTrack\Rest\Client\YouTrackClient; +use Cog\YouTrack\Rest\HttpClient\GuzzleHttpClient; use Cog\YouTrack\Rest\Tests\Traits\HasFakeHttpResponses; +use GuzzleHttp\Client as HttpClient; /** * Class TestCase. @@ -23,4 +27,19 @@ abstract class FeatureTestCase extends TestCase { use HasFakeHttpResponses; + + protected function initializeClient(): YouTrackClient + { + $http = new GuzzleHttpClient(new HttpClient([ + 'base_uri' => env('YOUTRACK_BASE_URI'), + ])); + $authorizer = new TokenAuthorizer(env('YOUTRACK_TOKEN')); + + return new YouTrackClient($http, $authorizer); + } + + protected function stubsPath($path): string + { + return realpath(__DIR__ . '/stubs/' . $path); + } } diff --git a/tests/Traits/HasFakeHttpResponses.php b/tests/Traits/HasFakeHttpResponses.php index 49e91e3..6f6a9e8 100644 --- a/tests/Traits/HasFakeHttpResponses.php +++ b/tests/Traits/HasFakeHttpResponses.php @@ -180,7 +180,7 @@ private function unsetFakeResponseHeaders(ResponseInterface $response, array $he private function buildFakeRequestDirectoryPath(string $name): string { return sprintf( - '%s/../stub-responses/2017.2/%s', + '%s/../stubs/server-responses/2017.2/%s', __DIR__, ltrim($name, '/') ); } diff --git a/tests/stubs/attachments/logo.png b/tests/stubs/attachments/logo.png new file mode 100644 index 0000000..3fe6f7b Binary files /dev/null and b/tests/stubs/attachments/logo.png differ diff --git a/tests/stub-responses/2017.2/dummy/body.json b/tests/stubs/server-responses/2017.2/dummy/body.json similarity index 100% rename from tests/stub-responses/2017.2/dummy/body.json rename to tests/stubs/server-responses/2017.2/dummy/body.json diff --git a/tests/stub-responses/2017.2/incorrect-login/body.json b/tests/stubs/server-responses/2017.2/incorrect-login/body.json similarity index 100% rename from tests/stub-responses/2017.2/incorrect-login/body.json rename to tests/stubs/server-responses/2017.2/incorrect-login/body.json diff --git a/tests/stub-responses/2017.2/unauthorized/body.json b/tests/stubs/server-responses/2017.2/unauthorized/body.json similarity index 100% rename from tests/stub-responses/2017.2/unauthorized/body.json rename to tests/stubs/server-responses/2017.2/unauthorized/body.json diff --git a/tests/stub-responses/2017.2/unauthorized/headers.json b/tests/stubs/server-responses/2017.2/unauthorized/headers.json similarity index 100% rename from tests/stub-responses/2017.2/unauthorized/headers.json rename to tests/stubs/server-responses/2017.2/unauthorized/headers.json