Skip to content

Commit

Permalink
Merge pull request #5 from elmage/post-content-type-fix
Browse files Browse the repository at this point in the history
fixed post content type
  • Loading branch information
elmage authored Aug 19, 2020
2 parents b3cfb80 + 012c4a1 commit c7b2fc3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,17 @@ private function prepareOptions(array $params = array())
$options = array();

if (count($params) > 0) {
$options[RequestOptions::JSON] = $params;
$options[RequestOptions::FORM_PARAMS] = $params;
$options[RequestOptions::VERIFY] = false;
$body = json_encode($params);
} else {
$body = '';
}

$defaultHeaders = array(
'User-Agent' => 'elmage/textng/php/'.Client::VERSION,
'Content-Type' => 'application/json',
'Accept' => 'text/plain, application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
'Accept' => 'text/plain, application/json', 'text/html',
);

$options[RequestOptions::HEADERS] = $defaultHeaders;
Expand Down
9 changes: 5 additions & 4 deletions tests/Unit/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Elmage\TextNg\HttpClient;
use Elmage\TextNg\Configuration;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\RequestOptions;
use PHPUnit\Framework\Constraint\Callback;
use PHPUnit\Framework\MockObject\MockObject;
use GuzzleHttp\ClientInterface;
Expand Down Expand Up @@ -119,15 +120,15 @@ function ($request) use ($method, $path) {
);
}

private function isValidOptionsArray(array $headers = [], $json = true): Callback
private function isValidOptionsArray(array $headers = [], $form_params = true): Callback
{
return $this->callback(function ($options) use ($headers, $json) {
return $this->callback(function ($options) use ($headers, $form_params) {
$this->assertArrayHasKey('headers', $options);
$this->assertArrayHasKey('User-Agent', $options['headers']);
$this->assertArrayHasKey('Content-Type', $options['headers']);

if ($json) {
$this->assertArrayHasKey('json', $options);
if ($form_params) {
$this->assertArrayHasKey(RequestOptions::FORM_PARAMS, $options);
}

foreach ($headers as $header) {
Expand Down

0 comments on commit c7b2fc3

Please sign in to comment.