Compare commits

...

25 Commits

Author SHA1 Message Date
Alex e5a6ec40fc Update composer 2026-06-27 16:40:46 +03:00
Alex 9eb8783f40 Merge pull request #36 from tofers/patch-1
Change url address
2026-06-27 09:38:23 +03:00
Konstantin 40de64593b Change url address
Для корректной работы ваших чат-ботов и мини-приложений до 19 июля 2026 необходимо перенаправить HTTP-запросы с домена platform-api.max.ru на platform-api2.max.ru, а также добавить сертификат Минцифры в список доверенных
2026-06-25 12:53:49 +03:00
Alex dfe2147cd1 tag 1.6.3 2026-04-26 20:36:38 +03:00
Alex 3d958f3f92 Update tests 2026-04-26 20:28:07 +03:00
Alex f40dc12d0c Merge pull request #32 from imperiumbee/master
New button type clipboard
2026-04-26 19:04:43 +03:00
imperiumbee b726c96366 Merge branch 'BushlanovDev:master' into master 2026-04-25 18:41:05 +03:00
imperiumbee c41221cec7 New button type clipboard 2026-04-25 18:38:55 +03:00
Alex 4fdfca53ee tag 1.6.2 2026-04-17 20:21:29 +03:00
Alex 9df8ed8817 Merge pull request #31 from spyke113/master
add `psr/log` versions
2026-04-16 14:46:34 +03:00
szuev 455b36ba2a add psr/log versions 2026-04-16 13:05:58 +03:00
Alex efd6261490 Added chat admin permissions 2026-04-15 22:10:15 +03:00
Alex dd295efc3d tag 1.6.0 2026-03-22 09:23:35 +03:00
Alex 85231b0962 Removed deprecated DataAttachment 2026-03-21 09:44:40 +03:00
Alex 40742ddc60 Removed deprecated ReplyKeyboardAttachment #27 2026-03-20 22:55:36 +03:00
Alex 1e48123ee3 Updated webhook documentation #26 2026-03-13 20:54:49 +03:00
Alex affe904bed tag 1.5.1 2026-03-07 09:47:01 +03:00
Alex 6c4e0c8ca7 Merge pull request #24 from imperiumbee/master
Added payload param to openAppButton
2026-03-07 09:25:53 +03:00
imperiumbee 3eb3e07bfa Added payload param to openAppButton 2026-03-06 11:12:20 +03:00
Alex ab7ea25796 Месседжер MAX следит за пользователями VPN 2026-03-05 15:24:24 +03:00
Alex 2a97a15889 1.5.0 2025-12-20 20:36:59 +03:00
Alex e9904cec71 Merge pull request #23 from BushlanovDev/1.5.0
1.5.0
2025-12-20 20:35:00 +03:00
Alex 67463a6b64 Replacing the User object with UserWithPhoto #22 2025-12-19 13:30:36 +03:00
Alex 3c6da8e8f6 Added MessageButton & ChatAdminPermission::EditLink & alias in ChatAdmin & participants in Chat & first_name in BotPatch 2025-12-18 19:50:58 +03:00
Alex cbb4cbcf0e Removed the typo 2025-12-10 21:51:13 +03:00
83 changed files with 403 additions and 548 deletions
+5 -2
View File
@@ -9,12 +9,15 @@
> [!CAUTION]
> На мой взгляд `Max Messenger` является ни чем иным как малварью, созданной для слежки за гражданами РФ. Настоятельно
> не рекомендую использовать его на реальных устройствах, с настоящим номером телефона, и для личной переписки.
> не рекомендую использовать его на реальных устройствах, с настоящим номером телефона, и для личной переписки.
> Обязательно к прочтению - [Месседжер MAX следит за пользователями VPN](https://habr.com/ru/articles/1006666/)
## Быстрый старт
> Если вы новичок, то можете прочитать [официальную документацию](https://dev.max.ru/), написанную разработчиками Max.
> ℹ️ С полной документацией [вы можете ознакомиться тут](./docs/README.md).
### Получение токена
Откройте диалог с [MasterBot](https://max.ru/MasterBot), следуйте инструкциям и создайте нового бота. После создания
@@ -102,7 +105,7 @@ $dispatcher->addHandler(UpdateType::BotStarted, function (BotStartedUpdate $upda
```php
$api->subscribe(
url: 'https://example.com/webhook', // URL на который будут приходить хуки
url: 'https://example.com/webhook', // HTTPS URL на который будут приходить хуки
secret: 'super_secret', // Секретная фраза для проверки хуков
updateTypes: [
// Типы хуков которые вы хотите получать (либо ничего не указывать, чтобы получать все)
+3 -3
View File
@@ -28,15 +28,15 @@
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0||^2.0",
"psr/log": "^3.0"
"psr/log": "^1.1||^2.0||^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.77",
"bushlanov-dev/php-coverage-badger": "^2.1",
"laravel/framework": "^11.0",
"laravel/framework": "^12.0",
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.6",
"orchestra/testbench": "^9.0",
"orchestra/testbench": "^10.0",
"php-mock/php-mock-phpunit": "^2.13",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^12.0",
+21 -4
View File
@@ -84,8 +84,25 @@ $api = new Api('YOUR_BOT_API_TOKEN');
Так же вы можете создать экземпляр бота гибко настроив все зависимости под свои нужды.
```php
$guzzle = new \GuzzleHttp\Client([
'timeout' => 10,
'connect_timeout' => 5,
'read_timeout' => 10,
'headers' => ['User-Agent' => 'max-bot-api-client-php'],
// 'verify' => false, либо путь до сертификата '/path/to/cert.pem'
]);
$httpFactory = new \GuzzleHttp\Psr7\HttpFactory();
$client = new \BushlanovDev\MaxMessengerBot\Client(
$accessToken,
$guzzle,
$httpFactory,
$httpFactory,
'https://platform-api2.max.ru',
);
$api = new Api(
client: new Client(...),
accessToken: 'YOUR_BOT_API_TOKEN',
client: $client,
modelFactory: new ModelFactory(),
logger: new YourPsrLogger(),
);
@@ -275,11 +292,11 @@ $subscriptions = $api->getSubscriptions();
Подписывает бота на получение обновлений через WebHook.
После вызова этого метода бот будет получать уведомления о новых событиях в чатах на указанный URL.
Ваш сервер должен прослушивать один из следующих портов: 80, 8080, 443, 8443, 16384-32383.
Судя по обновленной [документации](https://dev.max.ru/docs-api/methods/POST/subscriptions) поддерживается только 443 порт!
```php
$api->subscribe(
url: 'https://example.com/webhook', // URL на который будут приходить хуки. Должен начинаться с http(s)://
url: 'https://example.com/webhook', // HTTPS URL на который будут приходить хуки. Должен начинаться с https://
secret: 'super_secret', // Секретная фраза для проверки хуков (необязательно)
updateTypes: [UpdateType::MessageCreated], // Типы хуков которые вы хотите получать (либо ничего не указывать, чтобы получать все)
);
@@ -445,7 +462,7 @@ $api->answerOnCallback(
```
### Настройка
При не необходимости опубликовать конфиг выполните следующую команду:
При необходимости опубликовать конфиг выполните следующую команду:
```bash
php artisan vendor:publish --provider="BushlanovDev\MaxMessengerBot\Laravel\MaxBotServiceProvider"
+1 -1
View File
@@ -4656,4 +4656,4 @@
}
}
}
}
}
+2 -2
View File
@@ -48,11 +48,11 @@ use RuntimeException;
*/
class Api
{
public const string LIBRARY_VERSION = '1.4.2';
public const string LIBRARY_VERSION = '1.6.4';
public const string API_VERSION = '1.2.5';
private const string API_BASE_URL = 'https://platform-api.max.ru';
private const string API_BASE_URL = 'https://platform-api2.max.ru';
private const string METHOD_GET = 'GET';
private const string METHOD_POST = 'POST';
-2
View File
@@ -13,8 +13,6 @@ enum AttachmentType: string
case Sticker = 'sticker';
case Contact = 'contact';
case InlineKeyboard = 'inline_keyboard';
case ReplyKeyboard = 'reply_keyboard';
case Location = 'location';
case Share = 'share';
case Data = 'data';
}
+5
View File
@@ -15,4 +15,9 @@ enum ChatAdminPermission: string
case ChangeChatInfo = 'change_chat_info';
case PinMessage = 'pin_message';
case Write = 'write';
case CanCall = 'can_call';
case EditLink = 'edit_link';
case PostEditDeleteMessage = 'post_edit_delete_message';
case EditMessage = 'edit_message';
case DeleteMessage = 'delete_message';
}
+1
View File
@@ -13,4 +13,5 @@ enum InlineButtonType: string
case OpenApp = 'open_app';
case Message = 'message';
case Chat = 'chat';
case Clipboard = 'clipboard';
}
+5 -13
View File
@@ -14,7 +14,9 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\AudioAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\AbstractInlineButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\CallbackButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\ChatButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\ClipboardButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\LinkButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\MessageButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\OpenAppButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestContactButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestGeoLocationButton;
@@ -23,12 +25,10 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactBut
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendGeoLocationButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\ContactAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\DataAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\FileAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\InlineKeyboardAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\LocationAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\PhotoAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\ReplyKeyboardAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\ShareAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\StickerAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\VideoAttachment;
@@ -241,14 +241,6 @@ readonly class ModelFactory
public function createAttachment(array $data): AbstractAttachment
{
$attachmentType = AttachmentType::tryFrom($data['type'] ?? '');
if ($attachmentType === AttachmentType::ReplyKeyboard
&& isset($data['buttons']) && is_array($data['buttons'])) {
$data['buttons'] = array_map(
fn($rowOfButtons) => array_map([$this, 'createReplyButton'], $rowOfButtons),
$data['buttons'],
);
}
if ($attachmentType === AttachmentType::InlineKeyboard
&& isset($data['payload']['buttons']) && is_array($data['payload']['buttons'])) {
$data['payload']['buttons'] = array_map(
@@ -258,8 +250,6 @@ readonly class ModelFactory
}
return match ($attachmentType) {
AttachmentType::Data => DataAttachment::fromArray($data),
AttachmentType::Share => ShareAttachment::fromArray($data),
AttachmentType::Image => PhotoAttachment::fromArray($data),
AttachmentType::Video => VideoAttachment::fromArray($data),
AttachmentType::Audio => AudioAttachment::fromArray($data),
@@ -267,8 +257,8 @@ readonly class ModelFactory
AttachmentType::Sticker => StickerAttachment::fromArray($data),
AttachmentType::Contact => ContactAttachment::fromArray($data),
AttachmentType::InlineKeyboard => InlineKeyboardAttachment::fromArray($data),
AttachmentType::ReplyKeyboard => ReplyKeyboardAttachment::fromArray($data),
AttachmentType::Location => LocationAttachment::fromArray($data),
AttachmentType::Share => ShareAttachment::fromArray($data),
default => throw new LogicException('Unknown or unsupported attachment type: ' . ($data['type'] ?? 'none')),
};
}
@@ -311,6 +301,8 @@ readonly class ModelFactory
InlineButtonType::RequestGeoLocation => RequestGeoLocationButton::fromArray($data),
InlineButtonType::Chat => ChatButton::fromArray($data),
InlineButtonType::OpenApp => OpenAppButton::fromArray($data),
InlineButtonType::Clipboard => ClipboardButton::fromArray($data),
InlineButtonType::Message => MessageButton::fromArray($data),
default => throw new LogicException(
'Unknown or unsupported inline button type: ' . ($data['type'] ?? 'none')
),
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models;
final readonly class User extends AbstractModel
abstract readonly class AbstractUser extends AbstractModel
{
/**
* @param int $userId Users identifier.
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline;
use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType;
/**
* A button that, when clicked, copies text to the clipboard.
*/
final readonly class ClipboardButton extends AbstractInlineButton
{
public ?string $payload;
/**
* @param string $text Visible button text (1 to 128 characters).
* @param string $payload Text which will be copied.
*/
public function __construct(string $text, string $payload)
{
parent::__construct(InlineButtonType::Clipboard, $text);
$this->payload = $payload;
}
}
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline;
use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType;
/**
* Button send text in chat from user.
*/
final readonly class MessageButton extends AbstractInlineButton
{
/**
* @param string $text Text sending in chat from user.
*/
public function __construct(string $text)
{
parent::__construct(InlineButtonType::Message, $text);
}
}
@@ -13,17 +13,20 @@ final readonly class OpenAppButton extends AbstractInlineButton
{
public ?string $webApp;
public ?int $contactId;
public ?string $payload;
/**
* @param string $text Visible button text (1 to 128 characters).
* @param string|null $webApp The public name (username) of the bot or a link to it, whose mini-application should be launched.
* @param int|null $contactId The ID of the bot whose mini-app should be launched.
* @param string|null $payload Init param which would be passed in mini-application initData (1 to 512 characters, allowed A-Z, a-z, 0-9, _(underscore) , - (minus) ).
*/
public function __construct(string $text, ?string $webApp = null, ?int $contactId = null)
public function __construct(string $text, ?string $webApp = null, ?int $contactId = null, ?string $payload = null)
{
parent::__construct(InlineButtonType::OpenApp, $text);
$this->webApp = $webApp;
$this->contactId = $contactId;
$this->payload = $payload;
}
}
-21
View File
@@ -1,21 +0,0 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
/**
* Represents an attachment containing a payload from a SendMessageButton.
*/
final readonly class DataAttachment extends AbstractAttachment
{
/**
* @param string $data The payload from the button.
*/
public function __construct(public string $data)
{
parent::__construct(AttachmentType::Data);
}
}
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
/**
* Payload of a contact attachment.
@@ -14,11 +14,11 @@ final readonly class ContactAttachmentPayload extends AbstractModel
{
/**
* @param string|null $vcfInfo User info in VCF format.
* @param User|null $maxInfo User info if the contact is a Max user.
* @param UserWithPhoto|null $maxInfo User info if the contact is a Max user.
*/
public function __construct(
public ?string $vcfInfo,
public ?User $maxInfo,
public ?UserWithPhoto $maxInfo,
) {
}
}
@@ -1,22 +0,0 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
final readonly class ReplyKeyboardAttachmentRequestPayload extends AbstractAttachmentRequestPayload
{
/**
* @param AbstractReplyButton[][] $buttons Two-dimensional array of buttons.
* @param bool $direct Applicable only for chats.
* @param int|null $directUserId If set, reply keyboard will only be shown to this participant.
*/
public function __construct(
public array $buttons,
public bool $direct = false,
public ?int $directUserId = null,
) {
}
}
@@ -1,19 +0,0 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
final readonly class ReplyKeyboardAttachment extends AbstractAttachment
{
/**
* @param AbstractReplyButton[][] $buttons
*/
public function __construct(public array $buttons)
{
parent::__construct(AttachmentType::ReplyKeyboard);
}
}
@@ -1,28 +0,0 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Requests;
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ReplyKeyboardAttachmentRequestPayload;
final readonly class ReplyKeyboardAttachmentRequest extends AbstractAttachmentRequest
{
/**
* @param AbstractReplyButton[][] $buttons
* @param bool $direct
* @param int|null $directUserId
*/
public function __construct(
array $buttons,
bool $direct = false,
?int $directUserId = null
) {
parent::__construct(
AttachmentType::ReplyKeyboard,
new ReplyKeyboardAttachmentRequestPayload($buttons, $direct, $directUserId),
);
}
}
+8 -7
View File
@@ -9,7 +9,7 @@ use BushlanovDev\MaxMessengerBot\Attributes\ArrayOf;
/**
* Information about the current bot.
*/
final readonly class BotInfo extends AbstractModel
final readonly class BotInfo extends AbstractUser
{
/**
* @param int $userId ID user.
@@ -24,17 +24,18 @@ final readonly class BotInfo extends AbstractModel
* @param BotCommand[]|null $commands Commands supported by the bot (up to 32 elements).
*/
public function __construct(
public int $userId,
public string $firstName,
public ?string $lastName,
public ?string $username,
public bool $isBot,
public int $lastActivityTime,
int $userId,
string $firstName,
?string $lastName,
?string $username,
bool $isBot,
int $lastActivityTime,
public ?string $description,
public ?string $avatarUrl,
public ?string $fullAvatarUrl,
#[ArrayOf(BotCommand::class)]
public ?array $commands,
) {
parent::__construct($userId, $firstName, $lastName, $username, $isBot, $lastActivityTime);
}
}
+4 -2
View File
@@ -9,12 +9,14 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentRequ
/**
* Represents the data to patch for a bot. Instantiate with named arguments.
*
* Example: new BotPatch(name: 'New Bot Name', description: null);
* Example: new BotPatch(first_name: 'New Bot Name', description: null);
*
* @property-read string|null $name
* @property-read string|null $first_name
* @property-read string|null $last_name
* @property-read string|null $description
* @property-read BotCommand[]|null $commands
* @property-read PhotoAttachmentRequestPayload|null $photo
* @property-read string|null $name @deprecated Use first_name
*/
final readonly class BotPatch extends AbstractPatchModel
{
+2 -2
View File
@@ -13,13 +13,13 @@ final readonly class Callback extends AbstractModel
* @param int $timestamp Unix-time when user pressed the button.
* @param string $callbackId Identifier of the callback, unique for the message.
* @param string $payload Payload from the pressed button.
* @param User $user User who pressed the button.
* @param UserWithPhoto $user User who pressed the button.
*/
public function __construct(
public int $timestamp,
public string $callbackId,
public string $payload,
public User $user,
public UserWithPhoto $user,
) {
}
}
+2
View File
@@ -28,6 +28,7 @@ final readonly class Chat extends AbstractModel
* @param int|null $messagesCount Messages count in chat. Only for group chats and channels. Not available for dialogs.
* @param string|null $chatMessageId Identifier of message that contains `chat` button initialized chat.
* @param Message|null $pinnedMessage Pinned message in chat or channel. Returned only when single chat is requested.
* @param array<string, int>|null $participants List of participants in chat. Returned only when single chat is requested.
*/
public function __construct(
public int $chatId,
@@ -45,6 +46,7 @@ final readonly class Chat extends AbstractModel
public ?int $messagesCount,
public ?string $chatMessageId,
public ?Message $pinnedMessage,
public ?array $participants,
) {
}
}
+2
View File
@@ -15,11 +15,13 @@ final readonly class ChatAdmin extends AbstractModel
/**
* @param int $userId The identifier of the user to be made an admin.
* @param ChatAdminPermission[] $permissions The list of permissions to grant to the user.
* @param string|null $alias Alias of the user.
*/
public function __construct(
public int $userId,
#[ArrayOf(ChatAdminPermission::class)]
public array $permissions,
public ?string $alias = null,
) {
}
}
+10 -7
View File
@@ -10,7 +10,7 @@ use BushlanovDev\MaxMessengerBot\Enums\ChatAdminPermission;
/**
* Represents a member of a chat, including their user information and chat-specific status.
*/
final readonly class ChatMember extends AbstractModel
final readonly class ChatMember extends AbstractUser
{
/**
* @param int $userId User's identifier.
@@ -27,14 +27,15 @@ final readonly class ChatMember extends AbstractModel
* @param bool $isAdmin True if this member is an administrator of the chat.
* @param int $joinTime The time the user joined the chat.
* @param ChatAdminPermission[]|null $permissions A list of permissions if the member is an admin, otherwise null.
* @param string|null $alias Alias of the user.
*/
public function __construct(
public int $userId,
public string $firstName,
public ?string $lastName,
public ?string $username,
public bool $isBot,
public int $lastActivityTime,
int $userId,
string $firstName,
?string $lastName,
?string $username,
bool $isBot,
int $lastActivityTime,
public ?string $description,
public ?string $avatarUrl,
public ?string $fullAvatarUrl,
@@ -44,6 +45,8 @@ final readonly class ChatMember extends AbstractModel
public int $joinTime,
#[ArrayOf(ChatAdminPermission::class)]
public ?array $permissions,
public ?string $alias,
) {
parent::__construct($userId, $firstName, $lastName, $username, $isBot, $lastActivityTime);
}
}
+2 -2
View File
@@ -14,13 +14,13 @@ final readonly class LinkedMessage extends AbstractModel
/**
* @param MessageLinkType $type Type of linked message (forward or reply).
* @param MessageBody $message The body of the original message.
* @param User|null $sender The sender of the original message. Can be null if posted on behalf of a channel.
* @param UserWithPhoto|null $sender The sender of the original message. Can be null if posted on behalf of a channel.
* @param int|null $chatId The chat where the message was originally posted (for forwarded messages).
*/
public function __construct(
public MessageLinkType $type,
public MessageBody $message,
public ?User $sender,
public ?UserWithPhoto $sender,
public ?int $chatId,
) {
}
+2 -2
View File
@@ -13,7 +13,7 @@ final readonly class Message extends AbstractModel
* @param int $timestamp Unix-time when message was created.
* @param Recipient $recipient Message recipient. Could be user or chat.
* @param MessageBody|null $body Body of created message. Text + attachments.
* @param User|null $sender User who sent this message. Can be null if message has been posted on behalf of a channel.
* @param UserWithPhoto|null $sender User who sent this message. Can be null if message has been posted on behalf of a channel.
* @param string|null $url Message public URL. Can be null for dialogs or non-public chats/channels.
* @param LinkedMessage|null $link Forwarded or replied message.
* @param MessageStat|null $stat Message statistics. Available only for channels.
@@ -25,7 +25,7 @@ final readonly class Message extends AbstractModel
public int $timestamp,
public Recipient $recipient,
public ?MessageBody $body,
public ?User $sender,
public ?UserWithPhoto $sender,
public ?string $url,
public ?LinkedMessage $link,
public ?MessageStat $stat,
+3 -3
View File
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
/**
* You will receive this update when the bot has been added to a chat.
@@ -15,13 +15,13 @@ final readonly class BotAddedToChatUpdate extends AbstractUpdate
/**
* @param int $timestamp Unix-time when the event has occurred.
* @param int $chatId Chat ID where the bot was added.
* @param User $user User who added the bot to the chat.
* @param UserWithPhoto $user User who added the bot to the chat.
* @param bool $isChannel Indicates whether the bot has been added to a channel or not.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public bool $isChannel,
) {
parent::__construct(UpdateType::BotAdded, $timestamp);
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
/**
* You will receive this update when the bot has been removed from a chat.
@@ -15,13 +15,13 @@ final readonly class BotRemovedFromChatUpdate extends AbstractUpdate
/**
* @param int $timestamp Unix-time when the event has occurred.
* @param int $chatId Chat identifier the bot was removed from.
* @param User $user User who removed the bot from the chat.
* @param UserWithPhoto $user User who removed the bot from the chat.
* @param bool $isChannel Indicates whether the bot has been removed from a channel or not.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public bool $isChannel,
) {
parent::__construct(UpdateType::BotRemoved, $timestamp);
+3 -3
View File
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
/**
* Bot gets this type of update as soon as user pressed `Start` button.
@@ -15,14 +15,14 @@ final readonly class BotStartedUpdate extends AbstractUpdate
/**
* @param int $timestamp Unix-time when event has occurred.
* @param int $chatId Dialog identifier where event has occurred.
* @param User $user User pressed the 'Start' button.
* @param UserWithPhoto $user User pressed the 'Start' button.
* @param string|null $payload Additional data from deep-link passed on bot startup.
* @param string|null $userLocale Current user locale in IETF BCP 47 format.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public ?string $payload,
public ?string $userLocale,
) {
+3 -3
View File
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
/**
* The bot receives this type of update as soon as the user stops the bot.
@@ -15,13 +15,13 @@ final readonly class BotStoppedUpdate extends AbstractUpdate
/**
* @param int $timestamp Unix-time when event has occurred.
* @param int $chatId Dialog identifier where event has occurred.
* @param User $user User pressed the 'Start' button.
* @param UserWithPhoto $user User pressed the 'Start' button.
* @param string|null $userLocale Current user locale in IETF BCP 47 format.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public ?string $userLocale,
) {
parent::__construct(UpdateType::BotStopped, $timestamp);
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
/**
* Bot gets this type of update as soon as the title has been changed in a chat.
@@ -15,13 +15,13 @@ final readonly class ChatTitleChangedUpdate extends AbstractUpdate
/**
* @param int $timestamp Unix-time when the event has occurred.
* @param int $chatId Chat identifier where the event has occurred.
* @param User $user User who changed the title.
* @param UserWithPhoto $user User who changed the title.
* @param string $title The new title.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public string $title,
) {
parent::__construct(UpdateType::ChatTitleChanged, $timestamp);
+3 -3
View File
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
/**
* Event clearing dialog history.
@@ -15,13 +15,13 @@ final readonly class DialogClearedUpdate extends AbstractUpdate
/**
* @param int $timestamp Unix-time when event has occurred.
* @param int $chatId Dialog identifier where event has occurred.
* @param User $user User pressed the 'Start' button.
* @param UserWithPhoto $user User pressed the 'Start' button.
* @param string|null $userLocale Current user locale in IETF BCP 47 format.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public ?string $userLocale,
) {
parent::__construct(UpdateType::DialogCleared, $timestamp);
+3 -3
View File
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
/**
* Event when a user mutes a conversation with a bot.
@@ -15,14 +15,14 @@ final readonly class DialogMutedUpdate extends AbstractUpdate
/**
* @param int $timestamp Unix-time when event has occurred.
* @param int $chatId Dialog identifier where event has occurred.
* @param User $user User pressed the 'Start' button.
* @param UserWithPhoto $user User pressed the 'Start' button.
* @param int|null $mutedUntil The time in Unix format before which the dialog was disabled.
* @param string|null $userLocale Current user locale in IETF BCP 47 format.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public ?int $mutedUntil,
public ?string $userLocale,
) {
+3 -3
View File
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
/**
* Event deleting a chat.
@@ -15,13 +15,13 @@ final readonly class DialogRemovedUpdate extends AbstractUpdate
/**
* @param int $timestamp Unix-time when event has occurred.
* @param int $chatId Dialog identifier where event has occurred.
* @param User $user User pressed the 'Start' button.
* @param UserWithPhoto $user User pressed the 'Start' button.
* @param string|null $userLocale Current user locale in IETF BCP 47 format.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public ?string $userLocale,
) {
parent::__construct(UpdateType::DialogRemoved, $timestamp);
+3 -3
View File
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
/**
* Event of enabling notifications in a dialog.
@@ -15,13 +15,13 @@ final readonly class DialogUnmutedUpdate extends AbstractUpdate
/**
* @param int $timestamp Unix-time when event has occurred.
* @param int $chatId Dialog identifier where event has occurred.
* @param User $user User pressed the 'Start' button.
* @param UserWithPhoto $user User pressed the 'Start' button.
* @param string|null $userLocale Current user locale in IETF BCP 47 format.
*/
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public ?string $userLocale,
) {
parent::__construct(UpdateType::DialogUnmuted, $timestamp);
+3 -3
View File
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
/**
* You will receive this update when a user has been added to a chat where the bot is an administrator.
@@ -15,7 +15,7 @@ final readonly class UserAddedToChatUpdate extends AbstractUpdate
/**
* @param int $timestamp Unix-time when the event has occurred.
* @param int $chatId Chat identifier where the event has occurred.
* @param User $user User who was added to the chat.
* @param UserWithPhoto $user User who was added to the chat.
* @param int|null $inviterId User who added the new user to the chat.
* Can be `null` if the user joined via a link.
* @param bool $isChannel Indicates whether the user has been added to a channel or not.
@@ -23,7 +23,7 @@ final readonly class UserAddedToChatUpdate extends AbstractUpdate
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public ?int $inviterId,
public bool $isChannel,
) {
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
/**
* You will receive this update when a user has been removed from a chat where the bot is an administrator.
@@ -15,7 +15,7 @@ final readonly class UserRemovedFromChatUpdate extends AbstractUpdate
/**
* @param int $timestamp Unix-time when the event has occurred.
* @param int $chatId Chat identifier where the event has occurred.
* @param User $user User who was removed from the chat.
* @param UserWithPhoto $user User who was removed from the chat.
* @param int|null $adminId Administrator who removed the user from the chat.
* Can be `null` if the user left the chat themselves.
* @param bool $isChannel Indicates whether the user has been removed from a channel or not.
@@ -23,7 +23,7 @@ final readonly class UserRemovedFromChatUpdate extends AbstractUpdate
public function __construct(
int $timestamp,
public int $chatId,
public User $user,
public UserWithPhoto $user,
public ?int $adminId,
public bool $isChannel,
) {
+8 -7
View File
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models;
final readonly class UserWithPhoto extends AbstractModel
final readonly class UserWithPhoto extends AbstractUser
{
/**
* @param int $userId Users identifier.
@@ -18,15 +18,16 @@ final readonly class UserWithPhoto extends AbstractModel
* @param string|null $fullAvatarUrl URL of avatar of a bigger size.
*/
public function __construct(
public int $userId,
public string $firstName,
public ?string $lastName,
public ?string $username,
public bool $isBot,
public int $lastActivityTime,
int $userId,
string $firstName,
?string $lastName,
?string $username,
bool $isBot,
int $lastActivityTime,
public ?string $description,
public ?string $avatarUrl,
public ?string $fullAvatarUrl,
) {
parent::__construct($userId, $firstName, $lastName, $username, $isBot, $lastActivityTime);
}
}
+2
View File
@@ -10,6 +10,7 @@ use BushlanovDev\MaxMessengerBot\LongPollingHandler;
use BushlanovDev\MaxMessengerBot\ModelFactory;
use BushlanovDev\MaxMessengerBot\UpdateDispatcher;
use BushlanovDev\MaxMessengerBot\WebhookHandler;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
@@ -19,6 +20,7 @@ use Psr\Log\LoggerInterface;
use ReflectionClass;
#[CoversClass(Api::class)]
#[AllowMockObjectsWithoutExpectations]
#[UsesClass(UpdateDispatcher::class)]
#[UsesClass(WebhookHandler::class)]
#[UsesClass(LongPollingHandler::class)]
+8 -4
View File
@@ -47,7 +47,7 @@ use BushlanovDev\MaxMessengerBot\Models\Message;
use BushlanovDev\MaxMessengerBot\Models\MessageBody;
use BushlanovDev\MaxMessengerBot\Models\Recipient;
use BushlanovDev\MaxMessengerBot\Models\Result;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use BushlanovDev\MaxMessengerBot\Models\Subscription;
use BushlanovDev\MaxMessengerBot\Models\UpdateList;
use BushlanovDev\MaxMessengerBot\Models\Updates\AbstractUpdate;
@@ -62,6 +62,7 @@ use InvalidArgumentException;
use LogicException;
use org\bovigo\vfs\vfsStream;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
@@ -75,6 +76,7 @@ use ReflectionClass;
use RuntimeException;
#[CoversClass(Api::class)]
#[AllowMockObjectsWithoutExpectations]
#[UsesClass(Result::class)]
#[UsesClass(Client::class)]
#[UsesClass(BotInfo::class)]
@@ -82,7 +84,7 @@ use RuntimeException;
#[UsesClass(Message::class)]
#[UsesClass(MessageBody::class)]
#[UsesClass(Recipient::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
#[UsesClass(CallbackButton::class)]
#[UsesClass(InlineKeyboardAttachmentRequestPayload::class)]
#[UsesClass(InlineKeyboardAttachmentRequest::class)]
@@ -1667,12 +1669,14 @@ final class ApiTest extends TestCase
$admins = [
new ChatAdmin(101, [ChatAdminPermission::Write]),
new ChatAdmin(202, [ChatAdminPermission::PinMessage]),
new ChatAdmin(303, [ChatAdminPermission::EditMessage, ChatAdminPermission::CanCall], 'SuperUser'),
];
$expectedBody = [
'admins' => [
['user_id' => 101, 'permissions' => ['write']],
['user_id' => 202, 'permissions' => ['pin_message']],
['user_id' => 101, 'permissions' => ['write'], 'alias' => null],
['user_id' => 202, 'permissions' => ['pin_message'], 'alias' => null],
['user_id' => 303, 'permissions' => ['edit_message', 'can_call'], 'alias' => 'SuperUser'],
],
];
$rawResponse = ['success' => true];
+2
View File
@@ -16,6 +16,7 @@ use BushlanovDev\MaxMessengerBot\Exceptions\SerializationException;
use BushlanovDev\MaxMessengerBot\Exceptions\UnauthorizedException;
use GuzzleHttp\Psr7\HttpFactory;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
@@ -32,6 +33,7 @@ use Psr\Http\Message\StreamInterface;
use Psr\Log\LoggerInterface;
#[CoversClass(Client::class)]
#[AllowMockObjectsWithoutExpectations]
final class ClientTest extends TestCase
{
private const string FAKE_TOKEN = '12345:abcdef';
@@ -7,6 +7,7 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Laravel\Commands;
use BushlanovDev\MaxMessengerBot\Laravel\Commands\PollingStartCommand;
use BushlanovDev\MaxMessengerBot\Laravel\MaxBotManager;
use Illuminate\Support\Facades\Log;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
@@ -15,6 +16,7 @@ use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Tester\CommandTester;
#[CoversClass(PollingStartCommand::class)]
#[AllowMockObjectsWithoutExpectations]
#[UsesClass(MaxBotManager::class)]
final class PollingStartCommandTest extends TestCase
{
@@ -9,6 +9,7 @@ use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Laravel\Commands\WebhookListCommand;
use BushlanovDev\MaxMessengerBot\Models\Subscription;
use Illuminate\Support\Facades\Log;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
@@ -17,6 +18,7 @@ use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Tester\CommandTester;
#[CoversClass(WebhookListCommand::class)]
#[AllowMockObjectsWithoutExpectations]
#[UsesClass(Api::class)]
#[UsesClass(Subscription::class)]
final class WebhookListCommandTest extends TestCase
@@ -10,6 +10,7 @@ use BushlanovDev\MaxMessengerBot\Laravel\Commands\WebhookSubscribeCommand;
use BushlanovDev\MaxMessengerBot\Models\Result;
use Illuminate\Contracts\Config\Repository as Config;
use Illuminate\Support\Facades\Log;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
@@ -18,6 +19,7 @@ use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Tester\CommandTester;
#[CoversClass(WebhookSubscribeCommand::class)]
#[AllowMockObjectsWithoutExpectations]
#[UsesClass(Api::class)]
#[UsesClass(Result::class)]
final class WebhookSubscribeCommandTest extends TestCase
@@ -8,6 +8,7 @@ use BushlanovDev\MaxMessengerBot\Api;
use BushlanovDev\MaxMessengerBot\Laravel\Commands\WebhookUnsubscribeCommand;
use BushlanovDev\MaxMessengerBot\Models\Result;
use Illuminate\Support\Facades\Log;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
@@ -16,6 +17,7 @@ use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Tester\CommandTester;
#[CoversClass(WebhookUnsubscribeCommand::class)]
#[AllowMockObjectsWithoutExpectations]
#[UsesClass(Api::class)]
#[UsesClass(Result::class)]
final class WebhookUnsubscribeCommandTest extends TestCase
+2
View File
@@ -20,6 +20,7 @@ use Illuminate\Container\Container;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Facade;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
@@ -28,6 +29,7 @@ use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
#[CoversClass(MaxBotManager::class)]
#[AllowMockObjectsWithoutExpectations]
#[UsesClass(Message::class)]
#[UsesClass(MessageBody::class)]
#[UsesClass(Recipient::class)]
@@ -22,6 +22,7 @@ use InvalidArgumentException;
use LogicException;
use Orchestra\Testbench\TestCase;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
@@ -33,6 +34,7 @@ use Psr\Log\NullLogger;
use ReflectionClass;
#[CoversClass(MaxBotServiceProvider::class)]
#[AllowMockObjectsWithoutExpectations]
#[UsesClass(Api::class)]
#[UsesClass(Client::class)]
#[UsesClass(UpdateDispatcher::class)]
+6 -4
View File
@@ -11,11 +11,12 @@ use BushlanovDev\MaxMessengerBot\LongPollingHandler;
use BushlanovDev\MaxMessengerBot\Models\UpdateList;
use BushlanovDev\MaxMessengerBot\Models\Updates\AbstractUpdate;
use BushlanovDev\MaxMessengerBot\Models\Updates\BotStartedUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use BushlanovDev\MaxMessengerBot\UpdateDispatcher;
use Error;
use Exception;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
@@ -26,11 +27,12 @@ use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
#[CoversClass(LongPollingHandler::class)]
#[AllowMockObjectsWithoutExpectations]
#[UsesClass(UpdateDispatcher::class)]
#[UsesClass(UpdateList::class)]
#[UsesClass(AbstractUpdate::class)]
#[UsesClass(BotStartedUpdate::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class LongPollingHandlerTest extends TestCase
{
use PHPMock;
@@ -77,7 +79,7 @@ final class LongPollingHandlerTest extends TestCase
public static function processUpdatesProvider(): array
{
$user = new User(1, 'Test', null, null, false, time());
$user = new UserWithPhoto(1, 'Test', null, null, false, time(), null, null, null);
$update1 = new BotStartedUpdate(time(), 1, $user, null, null);
$update2 = new BotStartedUpdate(time(), 2, $user, null, null);
@@ -167,7 +169,7 @@ final class LongPollingHandlerTest extends TestCase
$dispatcher = new UpdateDispatcher($apiMock, $loggerMock);
$user = new User(1, 'Test', null, null, false, time());
$user = new UserWithPhoto(1, 'Test', null, null, false, time(), null, null, null);
$updateToFail = new BotStartedUpdate(time(), 1, $user, null, null);
$updateToSucceed = new BotStartedUpdate(time(), 2, $user, null, null);
+7 -44
View File
@@ -18,7 +18,6 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestGeoLoc
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\DataAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\InlineKeyboardAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\LocationAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\KeyboardPayload;
@@ -26,7 +25,6 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentPayl
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentRequestPayload;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ShareAttachmentRequestPayload;
use BushlanovDev\MaxMessengerBot\Models\Attachments\PhotoAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\ReplyKeyboardAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\ShareAttachment;
use BushlanovDev\MaxMessengerBot\Models\BotCommand;
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
@@ -42,7 +40,6 @@ use BushlanovDev\MaxMessengerBot\Models\Message;
use BushlanovDev\MaxMessengerBot\Models\MessageBody;
use BushlanovDev\MaxMessengerBot\Models\Recipient;
use BushlanovDev\MaxMessengerBot\Models\Result;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\Subscription;
use BushlanovDev\MaxMessengerBot\Models\UpdateList;
use BushlanovDev\MaxMessengerBot\Models\Updates\BotStartedUpdate;
@@ -70,7 +67,6 @@ use Psr\Log\LoggerInterface;
#[UsesClass(Message::class)]
#[UsesClass(MessageBody::class)]
#[UsesClass(Recipient::class)]
#[UsesClass(User::class)]
#[UsesClass(UpdateList::class)]
#[UsesClass(BotStartedUpdate::class)]
#[UsesClass(MessageCreatedUpdate::class)]
@@ -87,7 +83,6 @@ use Psr\Log\LoggerInterface;
#[UsesClass(PhotoAttachmentRequestPayload::class)]
#[UsesClass(VideoUrls::class)]
#[UsesClass(AbstractAttachment::class)]
#[UsesClass(DataAttachment::class)]
#[UsesClass(ShareAttachment::class)]
#[UsesClass(ShareAttachmentRequestPayload::class)]
#[UsesClass(LinkMarkup::class)]
@@ -98,7 +93,6 @@ use Psr\Log\LoggerInterface;
#[UsesClass(AbstractReplyButton::class)]
#[UsesClass(SendContactButton::class)]
#[UsesClass(SendMessageButton::class)]
#[UsesClass(ReplyKeyboardAttachment::class)]
#[UsesClass(AbstractInlineButton::class)]
#[UsesClass(ChatButton::class)]
#[UsesClass(RequestContactButton::class)]
@@ -282,7 +276,7 @@ final class ModelFactoryTest extends TestCase
$this->assertInstanceOf(Message::class, $message);
$this->assertInstanceOf(MessageBody::class, $message->body);
$this->assertInstanceOf(Recipient::class, $message->recipient);
$this->assertInstanceOf(User::class, $message->sender);
$this->assertInstanceOf(UserWithPhoto::class, $message->sender);
}
#[Test]
@@ -458,6 +452,7 @@ final class ModelFactoryTest extends TestCase
'is_admin' => true,
'join_time' => 1678000000,
'permissions' => ['pin_message', 'write'],
'alias' => null,
];
$chatMember = $this->factory->createChatMember($rawData);
@@ -594,7 +589,6 @@ final class ModelFactoryTest extends TestCase
'seq' => 102,
'text' => 'Message with data attachment',
'attachments' => [
['type' => 'data', 'data' => 'payload_from_reply_button'],
[
'type' => 'share',
'payload' => ['url' => 'http://a.com'],
@@ -616,16 +610,13 @@ final class ModelFactoryTest extends TestCase
$this->assertInstanceOf(Message::class, $message);
$this->assertInstanceOf(MessageBody::class, $message->body);
$this->assertIsArray($attachments);
$this->assertCount(3, $attachments);
$this->assertCount(2, $attachments);
$this->assertInstanceOf(DataAttachment::class, $attachments[0]);
$this->assertSame('payload_from_reply_button', $attachments[0]->data);
$this->assertInstanceOf(ShareAttachment::class, $message->body->attachments[0]);
$this->assertSame('Test Share', $attachments[0]->title);
$this->assertInstanceOf(ShareAttachment::class, $message->body->attachments[1]);
$this->assertSame('Test Share', $attachments[1]->title);
$this->assertInstanceOf(PhotoAttachment::class, $attachments[2]);
$this->assertSame(1, $attachments[2]->payload->photoId);
$this->assertInstanceOf(PhotoAttachment::class, $attachments[1]);
$this->assertSame(1, $attachments[1]->payload->photoId);
}
#[Test]
@@ -666,26 +657,6 @@ final class ModelFactoryTest extends TestCase
$this->factory->createMarkupElement(['type' => 'brand_new_unsupported_type']);
}
#[Test]
public function createAttachmentCorrectlyHydratesReplyKeyboard(): void
{
$data = [
'type' => 'reply_keyboard',
'buttons' => [
[['type' => 'message', 'text' => 'Hello']],
[['type' => 'user_contact', 'text' => 'My Contact']]
]
];
$attachment = $this->factory->createAttachment($data);
$this->assertInstanceOf(ReplyKeyboardAttachment::class, $attachment);
$this->assertCount(2, $attachment->buttons);
$this->assertInstanceOf(SendMessageButton::class, $attachment->buttons[0][0]);
$this->assertInstanceOf(SendContactButton::class, $attachment->buttons[1][0]);
$this->assertSame('My Contact', $attachment->buttons[1][0]->text);
}
#[Test]
public function createReplyButtonThrowsExceptionForUnknownType(): void
{
@@ -770,14 +741,6 @@ final class ModelFactoryTest extends TestCase
public static function attachmentTypeProvider(): array
{
return [
'Data Attachment' => [
['type' => 'data', 'data' => 'test_payload'],
DataAttachment::class,
function (TestCase $test, DataAttachment $attachment) {
$test->assertSame('test_payload', $attachment->data);
}
],
'Location Attachment' => [
['type' => 'location', 'latitude' => 55.751244, 'longitude' => 37.618423],
LocationAttachment::class,
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons\Inline;
use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\ClipboardButton;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
#[CoversClass(ClipboardButton::class)]
final class ClipboardButtonTest extends TestCase
{
#[Test]
public function toArraySerializesCorrectly(): void
{
$button = new ClipboardButton('display', 'copy');
$expectedArray = [
'payload' => 'copy',
'type' => InlineButtonType::Clipboard->value,
'text' => 'display',
];
$resultArray = $button->toArray();
$this->assertSame($expectedArray, $resultArray);
}
#[Test]
public function fromArrayHydratesCorrectly(): void
{
$data = [
'type' => 'clipboard',
'text' => 'display',
'payload' => 'copy'
];
$button = ClipboardButton::fromArray($data);
$this->assertInstanceOf(ClipboardButton::class, $button);
$this->assertSame(InlineButtonType::Clipboard, $button->type);
$this->assertSame('display', $button->text);
$this->assertSame('copy', $button->payload);
}
}
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons\Inline;
use BushlanovDev\MaxMessengerBot\Enums\InlineButtonType;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\MessageButton;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
#[CoversClass(MessageButton::class)]
final class MessageButtonTest extends TestCase
{
#[Test]
public function toArraySerializesCorrectly(): void
{
$button = new MessageButton('Test Button');
$expectedArray = [
'type' => InlineButtonType::Message->value,
'text' => 'Test Button',
];
$resultArray = $button->toArray();
$this->assertSame($expectedArray, $resultArray);
}
}
@@ -16,11 +16,12 @@ final class OpenAppButtonTest extends TestCase
#[Test]
public function toArraySerializesCorrectly(): void
{
$button = new OpenAppButton('Test Button', 'MyWebApp', 123);
$button = new OpenAppButton('Test Button', 'MyWebApp', 123, 'somePayload');
$expectedArray = [
'web_app' => 'MyWebApp',
'contact_id' => 123,
'payload' => 'somePayload',
'type' => InlineButtonType::OpenApp->value,
'text' => 'Test Button',
];
@@ -38,6 +39,7 @@ final class OpenAppButtonTest extends TestCase
'text' => 'Launch',
'web_app' => 'SomeApp',
'contact_id' => 456,
'payload' => 'somePayload'
];
$button = OpenAppButton::fromArray($data);
@@ -47,5 +49,6 @@ final class OpenAppButtonTest extends TestCase
$this->assertSame('Launch', $button->text);
$this->assertSame('SomeApp', $button->webApp);
$this->assertSame(456, $button->contactId);
$this->assertSame('somePayload', $button->payload);
}
}
@@ -6,7 +6,7 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
use BushlanovDev\MaxMessengerBot\Models\Attachments\ContactAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ContactAttachmentPayload;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
@@ -14,7 +14,7 @@ use PHPUnit\Framework\TestCase;
#[CoversClass(ContactAttachment::class)]
#[UsesClass(ContactAttachmentPayload::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class ContactAttachmentTest extends TestCase
{
#[Test]
@@ -1,49 +0,0 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
use BushlanovDev\MaxMessengerBot\Models\Attachments\AbstractAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\DataAttachment;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(DataAttachment::class)]
#[UsesClass(AbstractAttachment::class)]
final class DataAttachmentTest extends TestCase
{
#[Test]
public function canBeCreatedAndSerialized(): void
{
$attachment = new DataAttachment('some_payload_from_button');
$this->assertSame(AttachmentType::Data, $attachment->type);
$this->assertSame('some_payload_from_button', $attachment->data);
$expectedArray = [
'type' => 'data',
'data' => 'some_payload_from_button',
];
$this->assertEquals($expectedArray, $attachment->toArray());
}
#[Test]
public function canBeCreatedFromArray(): void
{
$data = [
'type' => 'data',
'data' => 'payload123',
];
$attachment = DataAttachment::fromArray($data);
$this->assertInstanceOf(DataAttachment::class, $attachment);
$this->assertSame(AttachmentType::Data, $attachment->type);
$this->assertSame('payload123', $attachment->data);
}
}
@@ -5,20 +5,20 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Payloads;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ContactAttachmentPayload;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(ContactAttachmentPayload::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class ContactAttachmentPayloadTest extends TestCase
{
#[Test]
public function canBeCreatedAndSerialized(): void
{
$user = User::fromArray(
$user = UserWithPhoto::fromArray(
['user_id' => 101, 'first_name' => 'MaxUser', 'is_bot' => false, 'last_activity_time' => time()]
);
$payload = new ContactAttachmentPayload('vcf_info_string', $user);
@@ -1,99 +0,0 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Payloads;
use BushlanovDev\MaxMessengerBot\Enums\Intent;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ReplyKeyboardAttachmentRequestPayload;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(ReplyKeyboardAttachmentRequestPayload::class)]
#[UsesClass(SendMessageButton::class)]
#[UsesClass(SendContactButton::class)]
final class ReplyKeyboardAttachmentRequestPayloadTest extends TestCase
{
#[Test]
public function toArrayWithDefaults(): void
{
$buttons = [
[new SendMessageButton('Help')],
[new SendContactButton('Share Contact')],
];
$payload = new ReplyKeyboardAttachmentRequestPayload($buttons);
$expected = [
'buttons' => [
[
[
'type' => 'message',
'text' => 'Help',
'payload' => null,
'intent' => 'default',
],
],
[
[
'type' => 'user_contact',
'text' => 'Share Contact',
],
],
],
'direct' => false,
'direct_user_id' => null,
];
$this->assertEquals($expected, $payload->toArray());
}
#[Test]
public function toArrayWithAllParameters(): void
{
$buttons = [
[new SendMessageButton('Confirm', 'confirm-action', Intent::Positive)],
];
$payload = new ReplyKeyboardAttachmentRequestPayload(
buttons: $buttons,
direct: true,
directUserId: 987654321,
);
$expected = [
'buttons' => [
[
[
'type' => 'message',
'text' => 'Confirm',
'payload' => 'confirm-action',
'intent' => 'positive',
],
],
],
'direct' => true,
'direct_user_id' => 987654321,
];
$this->assertEquals($expected, $payload->toArray());
}
#[Test]
public function toArrayWithEmptyButtons(): void
{
$payload = new ReplyKeyboardAttachmentRequestPayload(buttons: []);
$expected = [
'buttons' => [],
'direct' => false,
'direct_user_id' => null,
];
$this->assertEquals($expected, $payload->toArray());
}
}
@@ -1,43 +0,0 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
use BushlanovDev\MaxMessengerBot\ModelFactory;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\ReplyKeyboardAttachment;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(ReplyKeyboardAttachment::class)]
#[UsesClass(AbstractReplyButton::class)]
#[UsesClass(SendContactButton::class)]
#[UsesClass(SendMessageButton::class)]
#[UsesClass(ModelFactory::class)]
final class ReplyKeyboardAttachmentTest extends TestCase
{
#[Test]
public function canBeCreatedFromArrayViaFactory(): void
{
$data = [
'type' => 'reply_keyboard',
'buttons' => [
[['type' => 'message', 'text' => 'Hello']],
[['type' => 'user_contact', 'text' => 'My Contact']]
]
];
$factory = new ModelFactory();
$attachment = $factory->createAttachment($data);
$this->assertInstanceOf(ReplyKeyboardAttachment::class, $attachment);
$this->assertCount(2, $attachment->buttons);
$this->assertInstanceOf(SendContactButton::class, $attachment->buttons[1][0]);
$this->assertSame('My Contact', $attachment->buttons[1][0]->text);
}
}
@@ -1,59 +0,0 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Requests;
use BushlanovDev\MaxMessengerBot\Enums\Intent;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ReplyKeyboardAttachmentRequestPayload;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\ReplyKeyboardAttachmentRequest;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(ReplyKeyboardAttachmentRequest::class)]
#[UsesClass(SendMessageButton::class)]
#[UsesClass(SendContactButton::class)]
#[UsesClass(ReplyKeyboardAttachmentRequestPayload::class)]
final class ReplyKeyboardAttachmentRequestTest extends TestCase
{
#[Test]
public function toArray(): void
{
$buttons = [
[new SendMessageButton('Help', 'help_payload', Intent::Positive)],
[new SendContactButton('Share Contact')],
];
$request = new ReplyKeyboardAttachmentRequest(buttons: $buttons, direct: true);
$expectedArray = [
'type' => 'reply_keyboard',
'payload' => [
'buttons' => [
[
[
'type' => 'message',
'text' => 'Help',
'payload' => 'help_payload',
'intent' => 'positive',
],
],
[
[
'type' => 'user_contact',
'text' => 'Share Contact',
],
],
],
'direct' => true,
'direct_user_id' => null,
],
];
$this->assertEquals($expectedArray, $request->toArray());
}
}
+7
View File
@@ -58,4 +58,11 @@ final class BotPatchTest extends TestCase
$patch = new BotPatch();
$this->assertEmpty($patch->toArray());
}
#[Test]
public function toArrayFirstAndLastName(): void
{
$patch = new BotPatch(first_name: 'New Name', last_name: null);
$this->assertEquals(['first_name' => 'New Name', 'last_name' => null], $patch->toArray());
}
}
+6 -3
View File
@@ -5,14 +5,14 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Tests\Models;
use BushlanovDev\MaxMessengerBot\Models\Callback;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(Callback::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class CallbackTest extends TestCase
{
#[Test]
@@ -29,6 +29,9 @@ final class CallbackTest extends TestCase
'last_activity_time' => 1678886000,
'last_name' => null,
'username' => null,
'description' => null,
'avatar_url' => null,
'full_avatar_url' => null,
],
];
@@ -38,7 +41,7 @@ final class CallbackTest extends TestCase
$this->assertSame(1678886400, $callback->timestamp);
$this->assertSame('cb.12345.abc', $callback->callbackId);
$this->assertSame('button_1_pressed', $callback->payload);
$this->assertInstanceOf(User::class, $callback->user);
$this->assertInstanceOf(UserWithPhoto::class, $callback->user);
$this->assertSame(101, $callback->user->userId);
$this->assertEquals($data, $callback->toArray());
}
+1
View File
@@ -24,6 +24,7 @@ final class ChatAdminTest extends TestCase
$expected = [
'user_id' => 123,
'permissions' => ['write', 'pin_message'],
'alias' => null,
];
$this->assertEquals($expected, $admin->toArray());
+2
View File
@@ -34,6 +34,7 @@ final class ChatMemberTest extends TestCase
'is_admin' => true,
'join_time' => 1678000000,
'permissions' => ['pin_message', 'write'],
'alias' => null,
];
$member = ChatMember::fromArray($data);
@@ -66,6 +67,7 @@ final class ChatMemberTest extends TestCase
'is_admin' => false,
'join_time' => 1678000001,
'permissions' => null,
'alias' => null,
];
$member = ChatMember::fromArray($data);
+5
View File
@@ -48,6 +48,10 @@ final class ChatTest extends TestCase
],
'messages_count' => 100,
'chat_message_id' => 'mid.123',
'participants' => [
'456' => 1678886400000,
'789' => 1678886500000,
],
];
$chat = Chat::fromArray($data);
@@ -99,5 +103,6 @@ final class ChatTest extends TestCase
$this->assertNull($chat->dialogWithUser);
$this->assertNull($chat->messagesCount);
$this->assertNull($chat->chatMessageId);
$this->assertNull($chat->participants);
}
}
+3 -3
View File
@@ -7,7 +7,7 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models;
use BushlanovDev\MaxMessengerBot\Enums\MessageLinkType;
use BushlanovDev\MaxMessengerBot\Models\LinkedMessage;
use BushlanovDev\MaxMessengerBot\Models\MessageBody;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
@@ -15,7 +15,7 @@ use PHPUnit\Framework\TestCase;
#[CoversClass(LinkedMessage::class)]
#[UsesClass(MessageBody::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class LinkedMessageTest extends TestCase
{
#[Test]
@@ -46,7 +46,7 @@ final class LinkedMessageTest extends TestCase
$this->assertSame(MessageLinkType::Reply, $linkedMessage->type);
$this->assertInstanceOf(MessageBody::class, $linkedMessage->message);
$this->assertSame('mid.original.123', $linkedMessage->message->mid);
$this->assertInstanceOf(User::class, $linkedMessage->sender);
$this->assertInstanceOf(UserWithPhoto::class, $linkedMessage->sender);
$this->assertSame(101, $linkedMessage->sender->userId);
$this->assertSame(98765, $linkedMessage->chatId);
}
+2 -2
View File
@@ -15,7 +15,7 @@ use BushlanovDev\MaxMessengerBot\Models\Markup\StrongMarkup;
use BushlanovDev\MaxMessengerBot\Models\Message;
use BushlanovDev\MaxMessengerBot\Models\MessageBody;
use BushlanovDev\MaxMessengerBot\Models\Recipient;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
@@ -32,7 +32,7 @@ use PHPUnit\Framework\TestCase;
#[UsesClass(StrongMarkup::class)]
#[UsesClass(Message::class)]
#[UsesClass(Recipient::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class MessageBodyTest extends TestCase
{
#[Test]
+6 -3
View File
@@ -9,7 +9,7 @@ use BushlanovDev\MaxMessengerBot\Models\Message;
use BushlanovDev\MaxMessengerBot\Models\MessageBody;
use BushlanovDev\MaxMessengerBot\Models\MessageStat;
use BushlanovDev\MaxMessengerBot\Models\Recipient;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
@@ -18,7 +18,7 @@ use PHPUnit\Framework\TestCase;
#[CoversClass(Message::class)]
#[UsesClass(MessageBody::class)]
#[UsesClass(Recipient::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
#[UsesClass(LinkedMessage::class)]
#[UsesClass(MessageStat::class)]
final class MessageTest extends TestCase
@@ -41,6 +41,9 @@ final class MessageTest extends TestCase
'markup' => null,
],
'sender' =>[
'description' => null,
'avatar_url' => null,
'full_avatar_url' => null,
'user_id' => 123,
'first_name' => 'John',
'last_name' => 'Doe',
@@ -75,7 +78,7 @@ final class MessageTest extends TestCase
$this->assertSame($data['timestamp'], $message->timestamp);
$this->assertInstanceOf(MessageBody::class, $message->body);
$this->assertInstanceOf(Recipient::class, $message->recipient);
$this->assertInstanceOf(User::class, $message->sender);
$this->assertInstanceOf(UserWithPhoto::class, $message->sender);
$this->assertSame($data['url'], $message->url);
$this->assertInstanceOf(MessageStat::class, $message->stat);
$this->assertSame(500, $message->stat->views);
@@ -6,14 +6,14 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\Updates\BotAddedToChatUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(BotAddedToChatUpdate::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class BotAddedToChatUpdateTest extends TestCase
{
#[Test]
@@ -30,6 +30,9 @@ final class BotAddedToChatUpdateTest extends TestCase
'last_activity_time' => 1678000000,
'last_name' => null,
'username' => null,
'description' => null,
'avatar_url' => null,
'full_avatar_url' => null,
],
'is_channel' => false,
];
@@ -41,7 +44,7 @@ final class BotAddedToChatUpdateTest extends TestCase
$this->assertSame(1679000000, $update->timestamp);
$this->assertSame(987654321, $update->chatId);
$this->assertFalse($update->isChannel);
$this->assertInstanceOf(User::class, $update->user);
$this->assertInstanceOf(UserWithPhoto::class, $update->user);
$this->assertSame(101, $update->user->userId);
$this->assertEquals($data, $update->toArray());
}
@@ -6,14 +6,14 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\Updates\BotRemovedFromChatUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(BotRemovedFromChatUpdate::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class BotRemovedFromChatUpdateTest extends TestCase
{
#[Test]
@@ -30,6 +30,9 @@ final class BotRemovedFromChatUpdateTest extends TestCase
'is_bot' => false,
'last_activity_time' => 1679000000,
'last_name' => null,
'description' => null,
'avatar_url' => null,
'full_avatar_url' => null,
],
'is_channel' => false,
];
@@ -41,7 +44,7 @@ final class BotRemovedFromChatUpdateTest extends TestCase
$this->assertSame(1679100000, $update->timestamp);
$this->assertSame(123456, $update->chatId);
$this->assertFalse($update->isChannel);
$this->assertInstanceOf(User::class, $update->user);
$this->assertInstanceOf(UserWithPhoto::class, $update->user);
$this->assertSame(555, $update->user->userId);
$this->assertEquals($data, $update->toArray());
}
@@ -6,14 +6,14 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\Updates\BotStartedUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(BotStartedUpdate::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class BotStartedUpdateTest extends TestCase
{
#[Test]
@@ -6,14 +6,14 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\Updates\BotStoppedUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(BotStoppedUpdate::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class BotStoppedUpdateTest extends TestCase
{
#[Test]
@@ -6,14 +6,14 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\Updates\ChatTitleChangedUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(ChatTitleChangedUpdate::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class ChatTitleChangedUpdateTest extends TestCase
{
#[Test]
@@ -30,6 +30,9 @@ final class ChatTitleChangedUpdateTest extends TestCase
'last_activity_time' => 1679999999,
'last_name' => null,
'username' => null,
'description' => null,
'avatar_url' => null,
'full_avatar_url' => null,
],
'title' => 'New Awesome Chat Title',
];
@@ -41,7 +44,7 @@ final class ChatTitleChangedUpdateTest extends TestCase
$this->assertSame(1680000000, $update->timestamp);
$this->assertSame(12345, $update->chatId);
$this->assertSame('New Awesome Chat Title', $update->title);
$this->assertInstanceOf(User::class, $update->user);
$this->assertInstanceOf(UserWithPhoto::class, $update->user);
$this->assertSame(54321, $update->user->userId);
$this->assertEquals($data, $update->toArray());
}
@@ -6,14 +6,14 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\Updates\DialogClearedUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(DialogClearedUpdate::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class DialogClearedUpdateTest extends TestCase
{
#[Test]
@@ -6,14 +6,14 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\Updates\DialogMutedUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(DialogMutedUpdate::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class DialogMutedUpdateTest extends TestCase
{
#[Test]
@@ -6,14 +6,14 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\Updates\DialogRemovedUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(DialogRemovedUpdate::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class DialogRemovedUpdateTest extends TestCase
{
#[Test]
@@ -6,14 +6,14 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\Updates\DialogUnmutedUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(DialogUnmutedUpdate::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class DialogUnmutedUpdateTest extends TestCase
{
#[Test]
@@ -10,7 +10,7 @@ use BushlanovDev\MaxMessengerBot\Models\Message;
use BushlanovDev\MaxMessengerBot\Models\MessageBody;
use BushlanovDev\MaxMessengerBot\Models\Recipient;
use BushlanovDev\MaxMessengerBot\Models\Updates\MessageCallbackUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
@@ -21,7 +21,7 @@ use PHPUnit\Framework\TestCase;
#[UsesClass(Message::class)]
#[UsesClass(MessageBody::class)]
#[UsesClass(Recipient::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class MessageCallbackUpdateTest extends TestCase
{
#[Test]
@@ -8,7 +8,7 @@ use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\Message;
use BushlanovDev\MaxMessengerBot\Models\MessageBody;
use BushlanovDev\MaxMessengerBot\Models\Recipient;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use BushlanovDev\MaxMessengerBot\Models\Updates\MessageEditedUpdate;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
@@ -19,7 +19,7 @@ use PHPUnit\Framework\TestCase;
#[UsesClass(Message::class)]
#[UsesClass(MessageBody::class)]
#[UsesClass(Recipient::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class MessageEditedUpdateTest extends TestCase
{
#[Test]
@@ -6,14 +6,14 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\Updates\UserAddedToChatUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(UserAddedToChatUpdate::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class UserAddedToChatUpdateTest extends TestCase
{
#[Test]
@@ -30,6 +30,9 @@ final class UserAddedToChatUpdateTest extends TestCase
'is_bot' => false,
'last_activity_time' => 1680000000,
'username' => null,
'description' => null,
'avatar_url' => null,
'full_avatar_url' => null,
],
'inviter_id' => 202,
'is_channel' => false,
@@ -42,7 +45,7 @@ final class UserAddedToChatUpdateTest extends TestCase
$this->assertSame(12345, $update->chatId);
$this->assertSame(202, $update->inviterId);
$this->assertFalse($update->isChannel);
$this->assertInstanceOf(User::class, $update->user);
$this->assertInstanceOf(UserWithPhoto::class, $update->user);
$this->assertSame(101, $update->user->userId);
$this->assertEquals($data, $update->toArray());
}
@@ -61,6 +64,9 @@ final class UserAddedToChatUpdateTest extends TestCase
'is_bot' => false,
'last_activity_time' => 1680000001,
'username' => null,
'description' => null,
'avatar_url' => null,
'full_avatar_url' => null,
],
'inviter_id' => null,
'is_channel' => true,
@@ -6,14 +6,14 @@ namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
use BushlanovDev\MaxMessengerBot\Models\Updates\UserRemovedFromChatUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(UserRemovedFromChatUpdate::class)]
#[UsesClass(User::class)]
#[UsesClass(UserWithPhoto::class)]
final class UserRemovedFromChatUpdateTest extends TestCase
{
#[Test]
@@ -30,6 +30,9 @@ final class UserRemovedFromChatUpdateTest extends TestCase
'is_bot' => false,
'last_activity_time' => 1681000000,
'username' => null,
'description' => null,
'avatar_url' => null,
'full_avatar_url' => null,
],
'admin_id' => 222,
'is_channel' => false,
@@ -42,7 +45,7 @@ final class UserRemovedFromChatUpdateTest extends TestCase
$this->assertSame(98765, $update->chatId);
$this->assertSame(222, $update->adminId);
$this->assertFalse($update->isChannel);
$this->assertInstanceOf(User::class, $update->user);
$this->assertInstanceOf(UserWithPhoto::class, $update->user);
$this->assertSame(111, $update->user->userId);
$this->assertEquals($data, $update->toArray());
}
@@ -61,6 +64,9 @@ final class UserRemovedFromChatUpdateTest extends TestCase
'is_bot' => false,
'last_activity_time' => 1681000001,
'username' => null,
'description' => null,
'avatar_url' => null,
'full_avatar_url' => null,
],
'admin_id' => null,
'is_channel' => true,
+12 -6
View File
@@ -4,18 +4,21 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Tests\Models;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
#[CoversClass(User::class)]
#[CoversClass(UserWithPhoto::class)]
final class UserTest extends TestCase
{
#[Test]
public function canBeCreatedFromArray(): void
{
$data = [
'description' => null,
'avatar_url' => null,
'full_avatar_url' => null,
'user_id' => 123,
'first_name' => 'John',
'last_name' => 'Doe',
@@ -24,9 +27,9 @@ final class UserTest extends TestCase
'last_activity_time' => 1678886400000,
];
$sender = User::fromArray($data);
$sender = UserWithPhoto::fromArray($data);
$this->assertInstanceOf(User::class, $sender);
$this->assertInstanceOf(UserWithPhoto::class, $sender);
$this->assertSame($data['user_id'], $sender->userId);
$this->assertSame($data['first_name'], $sender->firstName);
$this->assertSame($data['last_name'], $sender->lastName);
@@ -44,15 +47,18 @@ final class UserTest extends TestCase
public function canBeCreatedFromArrayWithOptionalDataNull(): void
{
$data = [
'description' => null,
'avatar_url' => null,
'full_avatar_url' => null,
'user_id' => 123,
'first_name' => 'John',
'is_bot' => false,
'last_activity_time' => 1678886400000,
];
$sender = User::fromArray($data);
$sender = UserWithPhoto::fromArray($data);
$this->assertInstanceOf(User::class, $sender);
$this->assertInstanceOf(UserWithPhoto::class, $sender);
$this->assertSame($data['user_id'], $sender->userId);
$this->assertSame($data['first_name'], $sender->firstName);
$this->assertNull($sender->lastName);
+3 -3
View File
@@ -16,15 +16,15 @@ final class UserWithPhotoTest extends TestCase
public function canBeCreatedFromArray(): void
{
$data = [
'description' => 'Description',
'avatar_url' => 'https://example.com/avatar.jpg',
'full_avatar_url' => 'https://example.com/full_avatar.jpg',
'user_id' => 123,
'first_name' => 'John',
'last_name' => 'Doe',
'username' => 'johndoe',
'is_bot' => false,
'last_activity_time' => 1678886400000,
'description' => 'Description',
'avatar_url' => 'https://example.com/avatar.jpg',
'full_avatar_url' => 'https://example.com/full_avatar.jpg',
];
$user = UserWithPhoto::fromArray($data);
+7 -5
View File
@@ -12,15 +12,17 @@ use BushlanovDev\MaxMessengerBot\Models\MessageBody;
use BushlanovDev\MaxMessengerBot\Models\Recipient;
use BushlanovDev\MaxMessengerBot\Models\Updates\BotStartedUpdate;
use BushlanovDev\MaxMessengerBot\Models\Updates\MessageCreatedUpdate;
use BushlanovDev\MaxMessengerBot\Models\User;
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
use BushlanovDev\MaxMessengerBot\UpdateDispatcher;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(UpdateDispatcher::class)]
#[UsesClass(User::class)]
#[AllowMockObjectsWithoutExpectations]
#[UsesClass(UserWithPhoto::class)]
#[UsesClass(BotStartedUpdate::class)]
#[UsesClass(Message::class)]
#[UsesClass(MessageBody::class)]
@@ -42,7 +44,7 @@ final class UpdateDispatcherTest extends TestCase
{
$wasCalled = false;
$user = new User(100, 'Test', 'User', 'testuser', false, time());
$user = new UserWithPhoto(100, 'Test', 'User', 'testuser', false, time(), null, null, null);
$update = new BotStartedUpdate(time(), 12345, $user, null, 'ru-RU');
$this->dispatcher->addHandler(
@@ -66,7 +68,7 @@ final class UpdateDispatcherTest extends TestCase
$messageHandlerCalled = false;
$messageBody = new MessageBody('mid1', 1, '/start with args', null, null);
$sender = new User(101, 'Cmd', 'Sender', 'cmdsender', false, time());
$sender = new UserWithPhoto(101, 'Cmd', 'Sender', 'cmdsender', false, time(), null, null, null);
$recipient = new Recipient(ChatType::Dialog, 101, null);
$message = new Message(time(), $recipient, $messageBody, $sender, null, null, null);
$update = new MessageCreatedUpdate(time(), $message, 'ru-RU');
@@ -96,7 +98,7 @@ final class UpdateDispatcherTest extends TestCase
$messageHandlerCalled = false;
$messageBody = new MessageBody('mid2', 2, 'Hello world', null, null);
$sender = new User(102, 'Msg', 'Sender', 'msgsender', false, time());
$sender = new UserWithPhoto(102, 'Msg', 'Sender', 'msgsender', false, time(), null, null, null);
$recipient = new Recipient(ChatType::Dialog, 102, null);
$message = new Message(time(), $recipient, $messageBody, $sender, null, null, null);
$update = new MessageCreatedUpdate(time(), $message, 'en-US');
+2
View File
@@ -19,6 +19,7 @@ use BushlanovDev\MaxMessengerBot\UpdateDispatcher;
use BushlanovDev\MaxMessengerBot\WebhookHandler;
use LogicException;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
@@ -32,6 +33,7 @@ use Psr\Http\Message\StreamInterface;
use Psr\Log\LoggerInterface;
#[CoversClass(WebhookHandler::class)]
#[AllowMockObjectsWithoutExpectations]
#[UsesClass(UpdateDispatcher::class)]
#[UsesClass(Message::class)]
#[UsesClass(MessageBody::class)]