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

Fix incorrect array values addition to GET request in PsrTelegramClient #53

Merged
merged 1 commit into from
Jun 27, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
`Vjik\TelegramBot\Api\Type\Update` namespace.
- Chg #30: Remove `TelegramRequestWithFilesInterface`.
- Bug #48: Fix incorrect string values addition to POST request with files in `PsrTelegramClient`.
- Bug #53: Fix incorrect array values addition to GET request in `PsrTelegramClient`.

## 0.1.0 June 10, 2024

Expand Down
7 changes: 6 additions & 1 deletion src/Client/PsrTelegramClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@ private function createPostRequest(TelegramRequestInterface $request): HttpReque

private function createGetRequest(TelegramRequestInterface $request): HttpRequestInterface
{
$queryParameters = [];
foreach ($request->getData() as $key => $value) {
$queryParameters[$key] = is_scalar($value) ? $value : json_encode($value, JSON_THROW_ON_ERROR);
}

return $this->httpRequestFactory->createRequest(
'GET',
$this->apiUrlGenerator->generate($request->getApiMethod(), $request->getData()),
$this->apiUrlGenerator->generate($request->getApiMethod(), $queryParameters),
);
}
}
7 changes: 5 additions & 2 deletions tests/Client/PsrTelegramClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testGet(): void
$httpRequestFactory
->expects($this->once())
->method('createRequest')
->with('GET', 'https://api.telegram.org/bot04062024/getMe?key=value')
->with('GET', 'https://api.telegram.org/bot04062024/getMe?key=value&array=%5B1%2C%22test%22%5D')
->willReturn($httpRequest);

$client = new PsrTelegramClient(
Expand All @@ -43,7 +43,10 @@ public function testGet(): void
new StreamFactory(),
);

$response = $client->send(new TelegramRequest(HttpMethod::GET, 'getMe', ['key' => 'value']));
$response = $client->send(new TelegramRequest(HttpMethod::GET, 'getMe', [
'key' => 'value',
'array' => [1, 'test'],
]));

$this->assertSame(201, $response->statusCode);
}
Expand Down
Loading