diff --git a/docs/swagger.json b/docs/swagger.json index 1957f60..a33ea0a 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -4656,4 +4656,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/Enums/ChatAdminPermission.php b/src/Enums/ChatAdminPermission.php index 2357fa9..609d231 100644 --- a/src/Enums/ChatAdminPermission.php +++ b/src/Enums/ChatAdminPermission.php @@ -15,4 +15,5 @@ enum ChatAdminPermission: string case ChangeChatInfo = 'change_chat_info'; case PinMessage = 'pin_message'; case Write = 'write'; + case EditLink = 'edit_link'; } diff --git a/src/ModelFactory.php b/src/ModelFactory.php index 15223e4..3e8f482 100644 --- a/src/ModelFactory.php +++ b/src/ModelFactory.php @@ -15,6 +15,7 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\CallbackButton; use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\ChatButton; 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; @@ -311,6 +312,7 @@ public function createInlineButton(array $data): AbstractInlineButton InlineButtonType::RequestGeoLocation => RequestGeoLocationButton::fromArray($data), InlineButtonType::Chat => ChatButton::fromArray($data), InlineButtonType::OpenApp => OpenAppButton::fromArray($data), + InlineButtonType::Message => MessageButton::fromArray($data), default => throw new LogicException( 'Unknown or unsupported inline button type: ' . ($data['type'] ?? 'none') ), diff --git a/src/Models/User.php b/src/Models/AbstractUser.php similarity index 93% rename from src/Models/User.php rename to src/Models/AbstractUser.php index e8d3043..dc243d7 100644 --- a/src/Models/User.php +++ b/src/Models/AbstractUser.php @@ -4,7 +4,7 @@ namespace BushlanovDev\MaxMessengerBot\Models; -final readonly class User extends AbstractModel +abstract readonly class AbstractUser extends AbstractModel { /** * @param int $userId Users identifier. diff --git a/src/Models/Attachments/Buttons/Inline/MessageButton.php b/src/Models/Attachments/Buttons/Inline/MessageButton.php new file mode 100644 index 0000000..c2746bc --- /dev/null +++ b/src/Models/Attachments/Buttons/Inline/MessageButton.php @@ -0,0 +1,21 @@ +|null $participants List of participants in chat. Returned only when single chat is requested. */ public function __construct( public int $chatId, @@ -45,6 +46,7 @@ public function __construct( public ?int $messagesCount, public ?string $chatMessageId, public ?Message $pinnedMessage, + public ?array $participants, ) { } } diff --git a/src/Models/ChatAdmin.php b/src/Models/ChatAdmin.php index 03ceaa8..3c264f4 100644 --- a/src/Models/ChatAdmin.php +++ b/src/Models/ChatAdmin.php @@ -15,11 +15,13 @@ /** * @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, ) { } } diff --git a/src/Models/ChatMember.php b/src/Models/ChatMember.php index a9cf1a4..d682168 100644 --- a/src/Models/ChatMember.php +++ b/src/Models/ChatMember.php @@ -10,7 +10,7 @@ /** * 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 @@ * @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 @@ public function __construct( public int $joinTime, #[ArrayOf(ChatAdminPermission::class)] public ?array $permissions, + public ?string $alias, ) { + parent::__construct($userId, $firstName, $lastName, $username, $isBot, $lastActivityTime); } } diff --git a/src/Models/LinkedMessage.php b/src/Models/LinkedMessage.php index c05dd63..378c60c 100644 --- a/src/Models/LinkedMessage.php +++ b/src/Models/LinkedMessage.php @@ -14,13 +14,13 @@ /** * @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, ) { } diff --git a/src/Models/Message.php b/src/Models/Message.php index 77ecd87..8e48a2f 100644 --- a/src/Models/Message.php +++ b/src/Models/Message.php @@ -13,7 +13,7 @@ * @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 @@ public function __construct( public int $timestamp, public Recipient $recipient, public ?MessageBody $body, - public ?User $sender, + public ?UserWithPhoto $sender, public ?string $url, public ?LinkedMessage $link, public ?MessageStat $stat, diff --git a/src/Models/Updates/BotAddedToChatUpdate.php b/src/Models/Updates/BotAddedToChatUpdate.php index 364a214..81dbe9a 100644 --- a/src/Models/Updates/BotAddedToChatUpdate.php +++ b/src/Models/Updates/BotAddedToChatUpdate.php @@ -5,7 +5,7 @@ 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 @@ /** * @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); diff --git a/src/Models/Updates/BotRemovedFromChatUpdate.php b/src/Models/Updates/BotRemovedFromChatUpdate.php index 5262da1..c822b13 100644 --- a/src/Models/Updates/BotRemovedFromChatUpdate.php +++ b/src/Models/Updates/BotRemovedFromChatUpdate.php @@ -5,7 +5,7 @@ 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 @@ /** * @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); diff --git a/src/Models/Updates/BotStartedUpdate.php b/src/Models/Updates/BotStartedUpdate.php index e8c3fec..e8c72e0 100644 --- a/src/Models/Updates/BotStartedUpdate.php +++ b/src/Models/Updates/BotStartedUpdate.php @@ -5,7 +5,7 @@ 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 @@ /** * @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, ) { diff --git a/src/Models/Updates/BotStoppedUpdate.php b/src/Models/Updates/BotStoppedUpdate.php index c3484a1..b6cab2b 100644 --- a/src/Models/Updates/BotStoppedUpdate.php +++ b/src/Models/Updates/BotStoppedUpdate.php @@ -5,7 +5,7 @@ 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 @@ /** * @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); diff --git a/src/Models/Updates/ChatTitleChangedUpdate.php b/src/Models/Updates/ChatTitleChangedUpdate.php index 1382bb0..8a84e48 100644 --- a/src/Models/Updates/ChatTitleChangedUpdate.php +++ b/src/Models/Updates/ChatTitleChangedUpdate.php @@ -5,7 +5,7 @@ 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 @@ /** * @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); diff --git a/src/Models/Updates/DialogClearedUpdate.php b/src/Models/Updates/DialogClearedUpdate.php index 3195522..a258c37 100644 --- a/src/Models/Updates/DialogClearedUpdate.php +++ b/src/Models/Updates/DialogClearedUpdate.php @@ -5,7 +5,7 @@ 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 @@ /** * @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); diff --git a/src/Models/Updates/DialogMutedUpdate.php b/src/Models/Updates/DialogMutedUpdate.php index 0124232..7acb2d8 100644 --- a/src/Models/Updates/DialogMutedUpdate.php +++ b/src/Models/Updates/DialogMutedUpdate.php @@ -5,7 +5,7 @@ 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 @@ /** * @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, ) { diff --git a/src/Models/Updates/DialogRemovedUpdate.php b/src/Models/Updates/DialogRemovedUpdate.php index 6e6569a..14e7f74 100644 --- a/src/Models/Updates/DialogRemovedUpdate.php +++ b/src/Models/Updates/DialogRemovedUpdate.php @@ -5,7 +5,7 @@ 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 @@ /** * @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); diff --git a/src/Models/Updates/DialogUnmutedUpdate.php b/src/Models/Updates/DialogUnmutedUpdate.php index 0dbd792..3155bfa 100644 --- a/src/Models/Updates/DialogUnmutedUpdate.php +++ b/src/Models/Updates/DialogUnmutedUpdate.php @@ -5,7 +5,7 @@ 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 @@ /** * @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); diff --git a/src/Models/Updates/UserAddedToChatUpdate.php b/src/Models/Updates/UserAddedToChatUpdate.php index c343563..744a9f9 100644 --- a/src/Models/Updates/UserAddedToChatUpdate.php +++ b/src/Models/Updates/UserAddedToChatUpdate.php @@ -5,7 +5,7 @@ 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 @@ /** * @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 @@ public function __construct( int $timestamp, public int $chatId, - public User $user, + public UserWithPhoto $user, public ?int $inviterId, public bool $isChannel, ) { diff --git a/src/Models/Updates/UserRemovedFromChatUpdate.php b/src/Models/Updates/UserRemovedFromChatUpdate.php index 878819a..d7bb30f 100644 --- a/src/Models/Updates/UserRemovedFromChatUpdate.php +++ b/src/Models/Updates/UserRemovedFromChatUpdate.php @@ -5,7 +5,7 @@ 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 @@ /** * @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 @@ public function __construct( int $timestamp, public int $chatId, - public User $user, + public UserWithPhoto $user, public ?int $adminId, public bool $isChannel, ) { diff --git a/src/Models/UserWithPhoto.php b/src/Models/UserWithPhoto.php index 0b352e4..35c8438 100644 --- a/src/Models/UserWithPhoto.php +++ b/src/Models/UserWithPhoto.php @@ -4,7 +4,7 @@ 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 @@ * @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); } } diff --git a/tests/ApiTest.php b/tests/ApiTest.php index eca9644..c9b8536 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -47,7 +47,7 @@ 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; @@ -82,7 +82,7 @@ #[UsesClass(Message::class)] #[UsesClass(MessageBody::class)] #[UsesClass(Recipient::class)] -#[UsesClass(User::class)] +#[UsesClass(UserWithPhoto::class)] #[UsesClass(CallbackButton::class)] #[UsesClass(InlineKeyboardAttachmentRequestPayload::class)] #[UsesClass(InlineKeyboardAttachmentRequest::class)] @@ -1671,8 +1671,8 @@ public function postAdminsCallsClientWithCorrectBody(): void $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], ], ]; $rawResponse = ['success' => true]; diff --git a/tests/LongPollingHandlerTest.php b/tests/LongPollingHandlerTest.php index 2e8d61e..0d6209b 100644 --- a/tests/LongPollingHandlerTest.php +++ b/tests/LongPollingHandlerTest.php @@ -11,7 +11,7 @@ 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; @@ -30,7 +30,7 @@ #[UsesClass(UpdateList::class)] #[UsesClass(AbstractUpdate::class)] #[UsesClass(BotStartedUpdate::class)] -#[UsesClass(User::class)] +#[UsesClass(UserWithPhoto::class)] final class LongPollingHandlerTest extends TestCase { use PHPMock; @@ -77,7 +77,7 @@ public function processUpdates( 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 +167,7 @@ public function processUpdatesContinuesAndLogsWhenHandlerThrows(): void $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); diff --git a/tests/ModelFactoryTest.php b/tests/ModelFactoryTest.php index 84f819d..4bbdc6f 100644 --- a/tests/ModelFactoryTest.php +++ b/tests/ModelFactoryTest.php @@ -42,7 +42,6 @@ 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 +69,6 @@ #[UsesClass(Message::class)] #[UsesClass(MessageBody::class)] #[UsesClass(Recipient::class)] -#[UsesClass(User::class)] #[UsesClass(UpdateList::class)] #[UsesClass(BotStartedUpdate::class)] #[UsesClass(MessageCreatedUpdate::class)] @@ -282,7 +280,7 @@ public function createMessage(): void $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 +456,7 @@ public function createChatMember() 'is_admin' => true, 'join_time' => 1678000000, 'permissions' => ['pin_message', 'write'], + 'alias' => null, ]; $chatMember = $this->factory->createChatMember($rawData); diff --git a/tests/Models/Attachments/Buttons/Inline/MessageButtonTest.php b/tests/Models/Attachments/Buttons/Inline/MessageButtonTest.php new file mode 100644 index 0000000..98d7c8e --- /dev/null +++ b/tests/Models/Attachments/Buttons/Inline/MessageButtonTest.php @@ -0,0 +1,30 @@ + InlineButtonType::Message->value, + 'text' => 'Test Button', + ]; + + $resultArray = $button->toArray(); + + $this->assertSame($expectedArray, $resultArray); + } +} diff --git a/tests/Models/Attachments/ContactAttachmentTest.php b/tests/Models/Attachments/ContactAttachmentTest.php index 4c0b150..b8c3f30 100644 --- a/tests/Models/Attachments/ContactAttachmentTest.php +++ b/tests/Models/Attachments/ContactAttachmentTest.php @@ -6,7 +6,7 @@ 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 @@ #[CoversClass(ContactAttachment::class)] #[UsesClass(ContactAttachmentPayload::class)] -#[UsesClass(User::class)] +#[UsesClass(UserWithPhoto::class)] final class ContactAttachmentTest extends TestCase { #[Test] diff --git a/tests/Models/Attachments/Payloads/ContactAttachmentPayloadTest.php b/tests/Models/Attachments/Payloads/ContactAttachmentPayloadTest.php index 456d2b8..6275f55 100644 --- a/tests/Models/Attachments/Payloads/ContactAttachmentPayloadTest.php +++ b/tests/Models/Attachments/Payloads/ContactAttachmentPayloadTest.php @@ -5,20 +5,20 @@ 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); diff --git a/tests/Models/BotPatchTest.php b/tests/Models/BotPatchTest.php index 93ad912..4270257 100644 --- a/tests/Models/BotPatchTest.php +++ b/tests/Models/BotPatchTest.php @@ -58,4 +58,11 @@ public function toArrayIsEmptyWhenNoArgumentsPassed(): void $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()); + } } diff --git a/tests/Models/CallbackTest.php b/tests/Models/CallbackTest.php index 474967a..a4ad3e2 100644 --- a/tests/Models/CallbackTest.php +++ b/tests/Models/CallbackTest.php @@ -5,14 +5,14 @@ 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 @@ public function canBeCreatedFromArray(): void 'last_activity_time' => 1678886000, 'last_name' => null, 'username' => null, + 'description' => null, + 'avatar_url' => null, + 'full_avatar_url' => null, ], ]; @@ -38,7 +41,7 @@ public function canBeCreatedFromArray(): void $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()); } diff --git a/tests/Models/ChatAdminTest.php b/tests/Models/ChatAdminTest.php index 9671125..64fa712 100644 --- a/tests/Models/ChatAdminTest.php +++ b/tests/Models/ChatAdminTest.php @@ -24,6 +24,7 @@ public function toArraySerializesCorrectly(): void $expected = [ 'user_id' => 123, 'permissions' => ['write', 'pin_message'], + 'alias' => null, ]; $this->assertEquals($expected, $admin->toArray()); diff --git a/tests/Models/ChatMemberTest.php b/tests/Models/ChatMemberTest.php index 4f207e0..fabdd96 100644 --- a/tests/Models/ChatMemberTest.php +++ b/tests/Models/ChatMemberTest.php @@ -34,6 +34,7 @@ public function canBeCreatedForAdmin(): void 'is_admin' => true, 'join_time' => 1678000000, 'permissions' => ['pin_message', 'write'], + 'alias' => null, ]; $member = ChatMember::fromArray($data); @@ -66,6 +67,7 @@ public function canBeCreatedForRegularMember(): void 'is_admin' => false, 'join_time' => 1678000001, 'permissions' => null, + 'alias' => null, ]; $member = ChatMember::fromArray($data); diff --git a/tests/Models/ChatTest.php b/tests/Models/ChatTest.php index 269d942..dc01d3c 100644 --- a/tests/Models/ChatTest.php +++ b/tests/Models/ChatTest.php @@ -48,6 +48,10 @@ public function canBeCreatedFromArray(): void ], 'messages_count' => 100, 'chat_message_id' => 'mid.123', + 'participants' => [ + '456' => 1678886400000, + '789' => 1678886500000, + ], ]; $chat = Chat::fromArray($data); @@ -99,5 +103,6 @@ public function canBeCreatedFromArrayWithOptionalDataNull(): void $this->assertNull($chat->dialogWithUser); $this->assertNull($chat->messagesCount); $this->assertNull($chat->chatMessageId); + $this->assertNull($chat->participants); } } diff --git a/tests/Models/LinkedMessageTest.php b/tests/Models/LinkedMessageTest.php index 96216dc..81fc5eb 100644 --- a/tests/Models/LinkedMessageTest.php +++ b/tests/Models/LinkedMessageTest.php @@ -7,7 +7,7 @@ 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 @@ #[CoversClass(LinkedMessage::class)] #[UsesClass(MessageBody::class)] -#[UsesClass(User::class)] +#[UsesClass(UserWithPhoto::class)] final class LinkedMessageTest extends TestCase { #[Test] @@ -46,7 +46,7 @@ public function canBeCreatedFromArray(): void $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); } diff --git a/tests/Models/MessageBodyTest.php b/tests/Models/MessageBodyTest.php index 0f1cbfd..830b2d3 100644 --- a/tests/Models/MessageBodyTest.php +++ b/tests/Models/MessageBodyTest.php @@ -15,7 +15,7 @@ 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 @@ #[UsesClass(StrongMarkup::class)] #[UsesClass(Message::class)] #[UsesClass(Recipient::class)] -#[UsesClass(User::class)] +#[UsesClass(UserWithPhoto::class)] final class MessageBodyTest extends TestCase { #[Test] diff --git a/tests/Models/MessageTest.php b/tests/Models/MessageTest.php index 11d4d15..a5bf3e0 100644 --- a/tests/Models/MessageTest.php +++ b/tests/Models/MessageTest.php @@ -9,7 +9,7 @@ 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 @@ #[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 @@ public function canBeCreatedFromArrayWithAllData(): void '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 @@ public function canBeCreatedFromArrayWithAllData(): void $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); diff --git a/tests/Models/Updates/BotAddedToChatUpdateTest.php b/tests/Models/Updates/BotAddedToChatUpdateTest.php index dc17131..8012f1a 100644 --- a/tests/Models/Updates/BotAddedToChatUpdateTest.php +++ b/tests/Models/Updates/BotAddedToChatUpdateTest.php @@ -6,14 +6,14 @@ 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 @@ public function canBeCreatedFromArrayAndSerialized(): void '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 @@ public function canBeCreatedFromArrayAndSerialized(): void $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()); } diff --git a/tests/Models/Updates/BotRemovedFromChatUpdateTest.php b/tests/Models/Updates/BotRemovedFromChatUpdateTest.php index cd4a17f..9f626d6 100644 --- a/tests/Models/Updates/BotRemovedFromChatUpdateTest.php +++ b/tests/Models/Updates/BotRemovedFromChatUpdateTest.php @@ -6,14 +6,14 @@ 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 @@ public function canBeCreatedFromArrayAndSerialized(): void '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 @@ public function canBeCreatedFromArrayAndSerialized(): void $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()); } diff --git a/tests/Models/Updates/BotStartedUpdateTest.php b/tests/Models/Updates/BotStartedUpdateTest.php index e359f92..56c508c 100644 --- a/tests/Models/Updates/BotStartedUpdateTest.php +++ b/tests/Models/Updates/BotStartedUpdateTest.php @@ -6,14 +6,14 @@ 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] diff --git a/tests/Models/Updates/BotStoppedUpdateTest.php b/tests/Models/Updates/BotStoppedUpdateTest.php index c49ce41..27a4954 100644 --- a/tests/Models/Updates/BotStoppedUpdateTest.php +++ b/tests/Models/Updates/BotStoppedUpdateTest.php @@ -6,14 +6,14 @@ 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] diff --git a/tests/Models/Updates/ChatTitleChangedUpdateTest.php b/tests/Models/Updates/ChatTitleChangedUpdateTest.php index f3325e9..1dd2cc0 100644 --- a/tests/Models/Updates/ChatTitleChangedUpdateTest.php +++ b/tests/Models/Updates/ChatTitleChangedUpdateTest.php @@ -6,14 +6,14 @@ 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 @@ public function canBeCreatedFromArrayAndSerialized(): void '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 @@ public function canBeCreatedFromArrayAndSerialized(): void $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()); } diff --git a/tests/Models/Updates/DialogClearedUpdateTest.php b/tests/Models/Updates/DialogClearedUpdateTest.php index 6546aa6..92ced74 100644 --- a/tests/Models/Updates/DialogClearedUpdateTest.php +++ b/tests/Models/Updates/DialogClearedUpdateTest.php @@ -6,14 +6,14 @@ 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] diff --git a/tests/Models/Updates/DialogMutedUpdateTest.php b/tests/Models/Updates/DialogMutedUpdateTest.php index 3b32af7..f130691 100644 --- a/tests/Models/Updates/DialogMutedUpdateTest.php +++ b/tests/Models/Updates/DialogMutedUpdateTest.php @@ -6,14 +6,14 @@ 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] diff --git a/tests/Models/Updates/DialogRemovedUpdateTest.php b/tests/Models/Updates/DialogRemovedUpdateTest.php index a712da6..dfb19c1 100644 --- a/tests/Models/Updates/DialogRemovedUpdateTest.php +++ b/tests/Models/Updates/DialogRemovedUpdateTest.php @@ -6,14 +6,14 @@ 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] diff --git a/tests/Models/Updates/DialogUnmutedUpdateTest.php b/tests/Models/Updates/DialogUnmutedUpdateTest.php index 5f94d35..e47ee5a 100644 --- a/tests/Models/Updates/DialogUnmutedUpdateTest.php +++ b/tests/Models/Updates/DialogUnmutedUpdateTest.php @@ -6,14 +6,14 @@ 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] diff --git a/tests/Models/Updates/MessageCallbackUpdateTest.php b/tests/Models/Updates/MessageCallbackUpdateTest.php index 0b7fb8f..ea2fae5 100644 --- a/tests/Models/Updates/MessageCallbackUpdateTest.php +++ b/tests/Models/Updates/MessageCallbackUpdateTest.php @@ -10,7 +10,7 @@ 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 @@ #[UsesClass(Message::class)] #[UsesClass(MessageBody::class)] #[UsesClass(Recipient::class)] -#[UsesClass(User::class)] +#[UsesClass(UserWithPhoto::class)] final class MessageCallbackUpdateTest extends TestCase { #[Test] diff --git a/tests/Models/Updates/MessageEditedUpdateTest.php b/tests/Models/Updates/MessageEditedUpdateTest.php index acb7947..d630ac5 100644 --- a/tests/Models/Updates/MessageEditedUpdateTest.php +++ b/tests/Models/Updates/MessageEditedUpdateTest.php @@ -8,7 +8,7 @@ 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 @@ #[UsesClass(Message::class)] #[UsesClass(MessageBody::class)] #[UsesClass(Recipient::class)] -#[UsesClass(User::class)] +#[UsesClass(UserWithPhoto::class)] final class MessageEditedUpdateTest extends TestCase { #[Test] diff --git a/tests/Models/Updates/UserAddedToChatUpdateTest.php b/tests/Models/Updates/UserAddedToChatUpdateTest.php index b1c2b98..d5d41c6 100644 --- a/tests/Models/Updates/UserAddedToChatUpdateTest.php +++ b/tests/Models/Updates/UserAddedToChatUpdateTest.php @@ -6,14 +6,14 @@ 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 @@ public function canBeCreatedWhenInvitedByUser(): void '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 @@ public function canBeCreatedWhenInvitedByUser(): void $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 @@ public function canBeCreatedWhenJoinedByLink(): void 'is_bot' => false, 'last_activity_time' => 1680000001, 'username' => null, + 'description' => null, + 'avatar_url' => null, + 'full_avatar_url' => null, ], 'inviter_id' => null, 'is_channel' => true, diff --git a/tests/Models/Updates/UserRemovedFromChatUpdateTest.php b/tests/Models/Updates/UserRemovedFromChatUpdateTest.php index 3590b7d..6e1ee56 100644 --- a/tests/Models/Updates/UserRemovedFromChatUpdateTest.php +++ b/tests/Models/Updates/UserRemovedFromChatUpdateTest.php @@ -6,14 +6,14 @@ 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 @@ public function canBeCreatedWhenRemovedByAdmin(): void '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 @@ public function canBeCreatedWhenRemovedByAdmin(): void $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 @@ public function canBeCreatedWhenUserLeft(): void 'is_bot' => false, 'last_activity_time' => 1681000001, 'username' => null, + 'description' => null, + 'avatar_url' => null, + 'full_avatar_url' => null, ], 'admin_id' => null, 'is_channel' => true, diff --git a/tests/Models/UserTest.php b/tests/Models/UserTest.php index 7c34a22..394a725 100644 --- a/tests/Models/UserTest.php +++ b/tests/Models/UserTest.php @@ -4,18 +4,21 @@ 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 @@ public function canBeCreatedFromArray(): void '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 @@ public function canBeCreatedFromArray(): void 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); diff --git a/tests/Models/UserWithPhotoTest.php b/tests/Models/UserWithPhotoTest.php index ac5f4f8..a8efa46 100644 --- a/tests/Models/UserWithPhotoTest.php +++ b/tests/Models/UserWithPhotoTest.php @@ -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); diff --git a/tests/UpdateDispatcherTest.php b/tests/UpdateDispatcherTest.php index 9a71235..e0c26ad 100644 --- a/tests/UpdateDispatcherTest.php +++ b/tests/UpdateDispatcherTest.php @@ -12,7 +12,7 @@ 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\CoversClass; use PHPUnit\Framework\Attributes\Test; @@ -20,7 +20,7 @@ use PHPUnit\Framework\TestCase; #[CoversClass(UpdateDispatcher::class)] -#[UsesClass(User::class)] +#[UsesClass(UserWithPhoto::class)] #[UsesClass(BotStartedUpdate::class)] #[UsesClass(Message::class)] #[UsesClass(MessageBody::class)] @@ -42,7 +42,7 @@ public function addHandlerAndDispatch(): void { $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 +66,7 @@ public function onCommandDispatch(): void $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 +96,7 @@ public function messageWithoutCommandTriggersGenericHandler(): void $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');