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

Fixes and tests #4

Merged
merged 55 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
b58bb5c
`ApiUrlGenerator`
vjik Jun 4, 2024
7b7b31d
`PsrTelegramClient`
vjik Jun 4, 2024
036c945
`ValueHelper` 1
vjik Jun 4, 2024
ba7a367
`ValueHelper` 2
vjik Jun 4, 2024
ee94a37
`ValueHelper` 3
vjik Jun 4, 2024
e9f0c8c
`ValueHelper` 4
vjik Jun 4, 2024
aa959ba
`TelegramRequest`
vjik Jun 4, 2024
d593e7f
Types 1
vjik Jun 4, 2024
e5e4ebb
Types 2
vjik Jun 4, 2024
ad024f4
Types 3
vjik Jun 4, 2024
6231880
Types 4
vjik Jun 4, 2024
83f6793
Types 5
vjik Jun 4, 2024
7299170
Types 6
vjik Jun 4, 2024
0b601fa
Types 7
vjik Jun 4, 2024
717a661
Types 8
vjik Jun 4, 2024
14e6e2a
Types 9
vjik Jun 4, 2024
8995fe0
Types 10
vjik Jun 4, 2024
4dff5b5
Types 11
vjik Jun 4, 2024
07b260c
Types 12
vjik Jun 4, 2024
a496a0f
Types 13
vjik Jun 4, 2024
7dbd78b
Types 14
vjik Jun 4, 2024
da9befc
Types 15
vjik Jun 4, 2024
ce555a2
Types 16
vjik Jun 4, 2024
3fe51da
Types 17
vjik Jun 4, 2024
9c6efd1
Types 18
vjik Jun 4, 2024
aec4d27
Types 19
vjik Jun 5, 2024
59cb801
Types 20
vjik Jun 5, 2024
0d0f42a
Types 21
vjik Jun 5, 2024
7ed246f
Types 22
vjik Jun 5, 2024
e04eaff
Types 23
vjik Jun 5, 2024
43f3e66
Types 24
vjik Jun 5, 2024
48a0f50
Types 25
vjik Jun 5, 2024
a7f1a53
Types 26
vjik Jun 5, 2024
c1d881a
Types 27
vjik Jun 5, 2024
175ce90
Types 28
vjik Jun 5, 2024
f46b71c
Types 29
vjik Jun 5, 2024
11ea2ef
Types 30
vjik Jun 5, 2024
ad4dd4f
Types 31
vjik Jun 5, 2024
45acbf5
Methods 1
vjik Jun 5, 2024
0c3c9a3
Method 2
vjik Jun 5, 2024
0edc0cb
Method 3
vjik Jun 5, 2024
a9cfccd
Update 1
vjik Jun 5, 2024
bf3d46a
Update 2
vjik Jun 5, 2024
d88203e
Update 3
vjik Jun 5, 2024
b3b9345
FailResult
vjik Jun 5, 2024
7575e30
TelegramBotApi 1
vjik Jun 5, 2024
b33d062
TelegramBotApi 2
vjik Jun 5, 2024
72a7374
TelegramBotApi 3
vjik Jun 5, 2024
e5f3cbb
TelegramBotApi 4
vjik Jun 5, 2024
792b9eb
Add real API test
vjik Jun 5, 2024
57fb24c
CI
vjik Jun 5, 2024
81aeee9
Badges
vjik Jun 5, 2024
bf3a791
Fix psalm
vjik Jun 5, 2024
2deebcc
Fix badges
vjik Jun 5, 2024
10792c2
Fix CI
vjik Jun 5, 2024
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
68 changes: 68 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
on:
pull_request:
push:
branches: [ 'master' ]

name: build

jobs:
tests:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest
- windows-latest

php:
- "8.2"
- "8.3"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install PHP with extensions.
uses: shivammathur/setup-php@v2
env:
update: true
with:
php-version: ${{ matrix.php }}
ini-values: date.timezone='UTC'
coverage: xdebug
tools: composer:v2

- name: Determine composer cache directory on Linux.
if: matrix.os == 'ubuntu-latest'
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Determine composer cache directory on Windows.
if: matrix.os == 'windows-latest'
run: echo "COMPOSER_CACHE_DIR=~\AppData\Local\Composer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Cache dependencies installed with composer.
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Update composer.
run: composer self-update

- name: Install dependencies with composer.
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run tests with phpunit.
run: vendor/bin/phpunit --colors=always --coverage-clover=coverage.xml

- name: Upload coverage to Codecov.
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Vjik Telegram Bot API

[![Latest Stable Version](https://poser.pugx.org/vjik/_____/v/stable.png)](https://packagist.org/packages/vjik/_____)
[![Total Downloads](https://poser.pugx.org/vjik/_____/downloads.png)](https://packagist.org/packages/vjik/_____)
[![Build status](https://github.com/vjik/_____/workflows/build/badge.svg)](https://github.com/vjik/_____/actions?query=workflow%3Abuild)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fvjik%2F_____%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/vjik/_____/master)
[![type-coverage](https://shepherd.dev/github/vjik/_____/coverage.svg)](https://shepherd.dev/github/vjik/_____)
[![static analysis](https://github.com/vjik/_____/workflows/static%20analysis/badge.svg)](https://github.com/vjik/_____/actions?query=workflow%3A%22static+analysis%22)
[![psalm-level](https://shepherd.dev/github/vjik/_____/level.svg)](https://shepherd.dev/github/vjik/_____)
[![Latest Stable Version](https://poser.pugx.org/vjik/telegram-bot-api/v/stable.png)](https://packagist.org/packages/vjik/telegram-bot-api)
[![Total Downloads](https://poser.pugx.org/vjik/telegram-bot-api/downloads.png)](https://packagist.org/packages/vjik/telegram-bot-api)
[![Build status](https://github.com/vjik/php-telegram-bot-api/workflows/build/badge.svg)](https://github.com/vjik/php-telegram-bot-api/actions?query=workflow%3Abuild)
[![Code coverage](https://codecov.io/gh/vjik/php-telegram-bot-api/graph/badge.svg?token=5SV9NWKMQZ)](https://codecov.io/gh/vjik/php-telegram-bot-api)
[![type-coverage](https://shepherd.dev/github/vjik/php-telegram-bot-api/coverage.svg)](https://shepherd.dev/github/vjik/php-telegram-bot-api)
[![static analysis](https://github.com/vjik/php-telegram-bot-api/workflows/static%20analysis/badge.svg)](https://github.com/vjik/php-telegram-bot-api/actions?query=workflow%3A%22static+analysis%22)
[![psalm-level](https://shepherd.dev/github/vjik/php-telegram-bot-api/level.svg)](https://shepherd.dev/github/vjik/php-telegram-bot-api)

The package ...

Expand Down
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@
<directory suffix=".php">./src</directory>
</include>
</source>

<groups>
<exclude>
<group>realApi</group>
</exclude>
</groups>
</phpunit>
3 changes: 3 additions & 0 deletions src/Client/ApiUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Vjik\TelegramBot\Api\Client;

/**
* @see https://core.telegram.org/bots/api#making-requests
*/
final readonly class ApiUrlGenerator
{
private string $baseUrl;
Expand Down
11 changes: 8 additions & 3 deletions src/Client/PsrTelegramClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ private function createPostRequest(TelegramRequestInterface $request): HttpReque
$streamBuilder->addResource($key, json_encode($value, JSON_THROW_ON_ERROR));
}
foreach ($files as $key => $file) {
$streamBuilder->addResource($key, $file->resource, array_filter([
'filename' => $file->filename,
]));
$streamBuilder->addResource(
$key,
$file->resource,
array_filter(
['filename' => $file->filename],
static fn(mixed $value): bool => $value !== null,
)
);
}
$body = $streamBuilder->build();
$contentType = 'multipart/form-data; boundary=' . $streamBuilder->getBoundary() . '; charset=utf-8';
Expand Down
6 changes: 3 additions & 3 deletions src/FailResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
final readonly class FailResult
{
public function __construct(
public ?string $description,
public mixed $error_code,
public ?ResponseParameters $parameters,
public TelegramRequestInterface $request,
public TelegramResponse $response,
public ?string $description = null,
public ?ResponseParameters $parameters = null,
public mixed $error_code = null,
) {
}
}
11 changes: 7 additions & 4 deletions src/Method/DeleteMyCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ public function getApiMethod(): string

public function getData(): array
{
return array_filter([
'scope' => $this->scope?->toRequestArray(),
'language_code' => $this->languageCode,
]);
return array_filter(
[
'scope' => $this->scope?->toRequestArray(),
'language_code' => $this->languageCode,
],
static fn(mixed $value): bool => $value !== null,
);
}

public function prepareResult(mixed $result): true
Expand Down
9 changes: 6 additions & 3 deletions src/Method/GetChatMenuButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ public function getApiMethod(): string

public function getData(): array
{
return array_filter([
'chat_id' => $this->chatId,
]);
return array_filter(
[
'chat_id' => $this->chatId,
],
static fn(mixed $value): bool => $value !== null,
);
}

public function prepareResult(mixed $result): MenuButton
Expand Down
11 changes: 7 additions & 4 deletions src/Method/GetMyCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ public function getApiMethod(): string

public function getData(): array
{
return array_filter([
'scope' => $this->scope?->toRequestArray(),
'language_code' => $this->languageCode,
]);
return array_filter(
[
'scope' => $this->scope?->toRequestArray(),
'language_code' => $this->languageCode,
],
static fn(mixed $value): bool => $value !== null,
);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/Method/GetMyDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ public function getApiMethod(): string

public function getData(): array
{
return array_filter([
'language_code' => $this->languageCode,
]);
return array_filter(
[
'language_code' => $this->languageCode,
],
static fn(mixed $value): bool => $value !== null,
);
}

public function prepareResult(mixed $result): BotDescription
Expand Down
9 changes: 6 additions & 3 deletions src/Method/GetMyName.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ public function getApiMethod(): string

public function getData(): array
{
return array_filter([
'language_code' => $this->languageCode,
]);
return array_filter(
[
'language_code' => $this->languageCode,
],
static fn(mixed $value): bool => $value !== null,
);
}

public function prepareResult(mixed $result): BotName
Expand Down
9 changes: 6 additions & 3 deletions src/Method/GetMyShortDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ public function getApiMethod(): string

public function getData(): array
{
return array_filter([
'language_code' => $this->languageCode,
]);
return array_filter(
[
'language_code' => $this->languageCode,
],
static fn(mixed $value): bool => $value !== null,
);
}

public function prepareResult(mixed $result): BotShortDescription
Expand Down
35 changes: 19 additions & 16 deletions src/Method/SendLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,25 @@ public function getApiMethod(): string

public function getData(): array
{
return array_filter([
'business_connection_id' => $this->businessConnectionId,
'chat_id' => $this->chatId,
'message_thread_id' => $this->messageThreadId,
'latitude' => $this->latitude,
'longitude' => $this->longitude,
'horizontal_accuracy' => $this->horizontalAccuracy,
'live_period' => $this->livePeriod,
'heading' => $this->heading,
'proximity_alert_radius' => $this->proximityAlertRadius,
'disable_notification' => $this->disableNotification,
'protect_content' => $this->protectContent,
'message_effect_id' => $this->messageEffectId,
'reply_parameters' => $this->replyParameters?->toRequestArray(),
'reply_markup' => $this->replyMarkup?->toRequestArray(),
]);
return array_filter(
[
'business_connection_id' => $this->businessConnectionId,
'chat_id' => $this->chatId,
'message_thread_id' => $this->messageThreadId,
'latitude' => $this->latitude,
'longitude' => $this->longitude,
'horizontal_accuracy' => $this->horizontalAccuracy,
'live_period' => $this->livePeriod,
'heading' => $this->heading,
'proximity_alert_radius' => $this->proximityAlertRadius,
'disable_notification' => $this->disableNotification,
'protect_content' => $this->protectContent,
'message_effect_id' => $this->messageEffectId,
'reply_parameters' => $this->replyParameters?->toRequestArray(),
'reply_markup' => $this->replyMarkup?->toRequestArray(),
],
static fn(mixed $value): bool => $value !== null,
);
}

public function prepareResult(mixed $result): Message
Expand Down
37 changes: 20 additions & 17 deletions src/Method/SendMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,26 @@ public function getApiMethod(): string

public function getData(): array
{
return array_filter([
'business_connection_id' => $this->businessConnectionId,
'chat_id' => $this->chatId,
'message_thread_id' => $this->messageThreadId,
'text' => $this->text,
'parse_mode' => $this->parseMode,
'entities' => $this->entities === null ? null : array_map(
static fn(MessageEntity $entity) => $entity->toRequestArray(),
$this->entities,
),
'link_preview_options' => $this->linkPreviewOptions?->toRequestArray(),
'disable_notification' => $this->disableNotification,
'protect_content' => $this->protectContent,
'message_effect_id' => $this->messageEffectId,
'reply_parameters' => $this->replyParameters?->toRequestArray(),
'reply_markup' => $this->replyMarkup?->toRequestArray(),
]);
return array_filter(
[
'business_connection_id' => $this->businessConnectionId,
'chat_id' => $this->chatId,
'message_thread_id' => $this->messageThreadId,
'text' => $this->text,
'parse_mode' => $this->parseMode,
'entities' => $this->entities === null ? null : array_map(
static fn(MessageEntity $entity) => $entity->toRequestArray(),
$this->entities,
),
'link_preview_options' => $this->linkPreviewOptions?->toRequestArray(),
'disable_notification' => $this->disableNotification,
'protect_content' => $this->protectContent,
'message_effect_id' => $this->messageEffectId,
'reply_parameters' => $this->replyParameters?->toRequestArray(),
'reply_markup' => $this->replyMarkup?->toRequestArray(),
],
static fn(mixed $value): bool => $value !== null,
);
}

public function prepareResult(mixed $result): Message
Expand Down
50 changes: 28 additions & 22 deletions src/Method/SendPhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,38 @@ public function getApiMethod(): string

public function getData(): array
{
return array_filter([
'chat_id' => $this->chatId,
'photo' => is_string($this->photo) ? $this->photo : null,
'business_connection_id' => $this->businessConnectionId,
'message_thread_id' => $this->messageThreadId,
'caption' => $this->caption,
'parse_mode' => $this->parseMode,
'caption_entities' => $this->captionEntities === null ? null : array_map(
static fn(MessageEntity $entity) => $entity->toRequestArray(),
$this->captionEntities,
),
'show_caption_above_media' => $this->showCaptionAboveMedia,
'has_spoiler' => $this->hasSpoiler,
'disable_notification' => $this->disableNotification,
'protect_content' => $this->protectContent,
'message_effect_id' => $this->messageEffectId,
'reply_parameters' => $this->replyParameters?->toRequestArray(),
'reply_markup' => $this->replyMarkup?->toRequestArray(),
]);
return array_filter(
[
'chat_id' => $this->chatId,
'photo' => is_string($this->photo) ? $this->photo : null,
'business_connection_id' => $this->businessConnectionId,
'message_thread_id' => $this->messageThreadId,
'caption' => $this->caption,
'parse_mode' => $this->parseMode,
'caption_entities' => $this->captionEntities === null ? null : array_map(
static fn(MessageEntity $entity) => $entity->toRequestArray(),
$this->captionEntities,
),
'show_caption_above_media' => $this->showCaptionAboveMedia,
'has_spoiler' => $this->hasSpoiler,
'disable_notification' => $this->disableNotification,
'protect_content' => $this->protectContent,
'message_effect_id' => $this->messageEffectId,
'reply_parameters' => $this->replyParameters?->toRequestArray(),
'reply_markup' => $this->replyMarkup?->toRequestArray(),
],
static fn(mixed $value): bool => $value !== null,
);
}

public function getFiles(): array
{
return array_filter([
'photo' => $this->photo instanceof InputFile ? $this->photo : null,
]);
return array_filter(
[
'photo' => $this->photo instanceof InputFile ? $this->photo : null,
],
static fn(mixed $value): bool => $value !== null,
);
}

public function prepareResult(mixed $result): Message
Expand Down
Loading
Loading