Skip to content

Commit

Permalink
Add missing argument type in buildOptions method signature (#41)
Browse files Browse the repository at this point in the history
Refactor buildOptions method of YouTrackClient
  • Loading branch information
Anton Komarev authored Jun 30, 2018
1 parent 82dba4f commit dae15a1
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 16 deletions.
21 changes: 16 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,39 @@

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
- `Cog\Contracts\YouTrack\Rest\Client\Exceptions\ClientException` extends `RuntimeException` instead of `Exception`
- `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)).

Expand Down Expand Up @@ -86,11 +96,12 @@ 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
[4.0.0]: https://github.com/cybercog/youtrack-rest-php/compare/3.2.0...4.0.0
[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
[2.0.1]: https://github.com/cybercog/youtrack-rest-php/compare/1.0.0...2.0.1
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017, Anton Komarev <[email protected]>
Copyright (c) 2018, Anton Komarev <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ If you discover any security related issues, please email [email protected] inste

## Contributors

| <a href="https://github.com/a-komarev">![@a-komarev](https://avatars.githubusercontent.com/u/1849174?s=110)<br />Anton Komarev</a> | <a href="https://github.com/adam187">![@adam187](https://avatars.githubusercontent.com/u/156628?s=110)<br />Adam Misiorny</a> |
| :---: | :---: |
| <a href="https://github.com/a-komarev">![@a-komarev](https://avatars.githubusercontent.com/u/1849174?s=110)<br />Anton Komarev</a> | <a href="https://github.com/adam187">![@adam187](https://avatars.githubusercontent.com/u/156628?s=110)<br />Adam Misiorny</a> | <a href="https://github.com/dmkdev"><br />dmkdev</a> |
| :---: | :---: | :---: |

[PHP YouTrack REST contributors list](../../contributors)

Expand Down
2 changes: 1 addition & 1 deletion contracts/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 8 additions & 6 deletions src/Client/YouTrackClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
19 changes: 19 additions & 0 deletions tests/FeatureTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion tests/Traits/HasFakeHttpResponses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/')
);
}
Expand Down
Binary file added tests/stubs/attachments/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.

0 comments on commit dae15a1

Please sign in to comment.