From e9f7838937a1edf95fbcaa620f414f43fbd81c9f Mon Sep 17 00:00:00 2001 From: BoShurik Date: Mon, 4 Sep 2023 16:31:53 +0300 Subject: [PATCH] my_chat_member, chat_member, chat_join_request updates and invite link methods --- CHANGELOG.md | 10 ++ composer.json | 9 +- src/BotApi.php | 112 ++++++++++++ src/Types/ChatInviteLink.php | 249 ++++++++++++++++++++++++++ src/Types/ChatJoinRequest.php | 174 ++++++++++++++++++ src/Types/ChatMemberUpdated.php | 199 ++++++++++++++++++++ src/Types/Update.php | 78 ++++++++ tests/Types/ChatInviteLinkTest.php | 74 ++++++++ tests/Types/ChatJoinRequestTest.php | 64 +++++++ tests/Types/ChatMemberUpdatedTest.php | 68 +++++++ tests/Types/UpdateTest.php | 13 +- 11 files changed, 1046 insertions(+), 4 deletions(-) create mode 100644 src/Types/ChatInviteLink.php create mode 100644 src/Types/ChatJoinRequest.php create mode 100644 src/Types/ChatMemberUpdated.php create mode 100644 tests/Types/ChatInviteLinkTest.php create mode 100644 tests/Types/ChatJoinRequestTest.php create mode 100644 tests/Types/ChatMemberUpdatedTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f532937..0a092388 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file +## 2.6.0 - YYYY-MM-DD +- Add `\TelegramBot\Api\Types\Update::$myChatMember` field +- Add `\TelegramBot\Api\Types\Update::$chatMember` field +- Add `\TelegramBot\Api\Types\Update::$chatJoinRequest` field +- Add `\TelegramBot\Api\BotApi::createChatInviteLink` api method +- Add `\TelegramBot\Api\BotApi::editChatInviteLink` api method +- Add `\TelegramBot\Api\BotApi::revokeChatInviteLink` api method +- Add `\TelegramBot\Api\BotApi::approveChatJoinRequest` api method +- Add `\TelegramBot\Api\BotApi::declineChatJoinRequest` api method + ## 2.5.0 - 2023-08-09 ### Added diff --git a/composer.json b/composer.json index 252b7ea0..24abe76d 100644 --- a/composer.json +++ b/composer.json @@ -42,11 +42,16 @@ "coverage": "XDEBUG_MODE=coverage vendor/bin/simple-phpunit --coverage-html build/coverage", "psalm": "vendor/bin/psalm", "cs-fix": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi", - "cs-check": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi --dry-run" + "cs-check": "vendor/bin/php-cs-fixer fix --allow-risky=yes --diff --ansi --dry-run", + "checks": [ + "@cs-fix", + "@psalm", + "@test" + ] }, "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "2.6-dev" } } } diff --git a/src/BotApi.php b/src/BotApi.php index 45feaa58..53ef612f 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -10,6 +10,7 @@ use TelegramBot\Api\Types\ArrayOfUpdates; use TelegramBot\Api\Types\BotCommand; use TelegramBot\Api\Types\Chat; +use TelegramBot\Api\Types\ChatInviteLink; use TelegramBot\Api\Types\ChatMember; use TelegramBot\Api\Types\File; use TelegramBot\Api\Types\ForceReply; @@ -2126,6 +2127,117 @@ public function exportChatInviteLink($chatId) ]); } + /** + * Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat + * for this to work and must have the appropriate administrator rights. + * The link can be revoked using the method revokeChatInviteLink. + * Returns the new invite link as ChatInviteLink object. + * + * @param int|string $chatId Unique identifier for the target chat or + * username of the target channel (in the format @channelusername) + * @param string|null $name Invite link name; 0-32 characters + * @param int|null $expireDate Point in time (Unix timestamp) when the link will expire + * @param int|null $memberLimit The maximum number of users that can be members of the chat simultaneously + * after joining the chat via this invite link; 1-99999 + * @param bool|null $createsJoinRequest True, if users joining the chat via the link need to be approved by chat administrators. + * If True, member_limit can't be specified + * @return ChatInviteLink + * @throws Exception + */ + public function createChatInviteLink($chatId, $name = null, $expireDate = null, $memberLimit = null, $createsJoinRequest = null) + { + return ChatInviteLink::fromResponse($this->call('createChatInviteLink', [ + 'chat_id' => $chatId, + 'name' => $name, + 'expire_date' => $expireDate, + 'member_limit' => $memberLimit, + 'creates_join_request' => $createsJoinRequest, + ])); + } + + /** + * Use this method to edit a non-primary invite link created by the bot. + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * Returns the edited invite link as a ChatInviteLink object. + * + * @param int|string $chatId Unique identifier for the target chat or + * username of the target channel (in the format @channelusername) + * @param string $inviteLink The invite link to edit + * @param string|null $name Invite link name; 0-32 characters + * @param int|null $expireDate Point in time (Unix timestamp) when the link will expire + * @param int|null $memberLimit The maximum number of users that can be members of the chat simultaneously + * after joining the chat via this invite link; 1-99999 + * @param bool|null $createsJoinRequest True, if users joining the chat via the link need to be approved by chat administrators. + * If True, member_limit can't be specified + * @return ChatInviteLink + * @throws Exception + */ + public function editChatInviteLink($chatId, $inviteLink, $name = null, $expireDate = null, $memberLimit = null, $createsJoinRequest = null) + { + return ChatInviteLink::fromResponse($this->call('editChatInviteLink', [ + 'chat_id' => $chatId, + 'invite_link' => $inviteLink, + 'name' => $name, + 'expire_date' => $expireDate, + 'member_limit' => $memberLimit, + 'creates_join_request' => $createsJoinRequest, + ])); + } + + /** + * Use this method to revoke an invite link created by the bot. + * If the primary link is revoked, a new link is automatically generated. + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * Returns the revoked invite link as ChatInviteLink object. + * + * @param int|string $chatId Unique identifier for the target chat or + * username of the target channel (in the format @channelusername) + * @param string $inviteLink The invite link to edit + * @return ChatInviteLink + * @throws Exception + */ + public function revokeChatInviteLink($chatId, $inviteLink) + { + return ChatInviteLink::fromResponse($this->call('revokeChatInviteLink', [ + 'chat_id' => $chatId, + 'invite_link' => $inviteLink, + ])); + } + + /** + * Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and + * must have the can_invite_users administrator right. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param int $userId Unique identifier of the target user + * @return bool + * @throws Exception + */ + public function approveChatJoinRequest($chatId, $userId) + { + return $this->call('approveChatJoinRequest', [ + 'chat_id' => $chatId, + 'user_id' => $userId, + ]); + } + + /** + * Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and + * must have the can_invite_users administrator right. Returns True on success. + * + * @param int|string $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param int $userId Unique identifier of the target user + * @return bool + * @throws Exception + */ + public function declineChatJoinRequest($chatId, $userId) + { + return $this->call('declineChatJoinRequest', [ + 'chat_id' => $chatId, + 'user_id' => $userId, + ]); + } + /** * Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. diff --git a/src/Types/ChatInviteLink.php b/src/Types/ChatInviteLink.php new file mode 100644 index 00000000..4cbfbbe5 --- /dev/null +++ b/src/Types/ChatInviteLink.php @@ -0,0 +1,249 @@ + true, + 'creator' => User::class, + 'creates_join_request' => true, + 'is_primary' => true, + 'is_revoked' => true, + 'name' => true, + 'expire_date' => true, + 'member_limit' => true, + 'pending_join_request_count' => true, + ]; + + /** + * The invite link. If the link was created by another chat administrator, then the second part of the link will be replaced with “…”. + * + * @var string + */ + protected $inviteLink; + + /** + * Creator of the link + * + * @var User + */ + protected $creator; + + /** + * True, if users joining the chat via the link need to be approved by chat administrators + * + * @var bool + */ + protected $createsJoinRequest; + + /** + * True, if the link is primary + * + * @var bool + */ + protected $isPrimary; + + /** + * True, if the link is revoked + * + * @var bool + */ + protected $isRevoked; + + /** + * Optional. Invite link name + * + * @var string|null + */ + protected $name; + + /** + * Optional. Point in time (Unix timestamp) when the link will expire or has been expired + * + * @var int|null + */ + protected $expireDate; + + /** + * Optional. The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999 + * + * @var int|null + */ + protected $memberLimit; + + /** + * Optional. Number of pending join requests created using this link + * + * @var int|null + */ + protected $pendingJoinRequestCount; + + /** + * @return string + */ + public function getInviteLink() + { + return $this->inviteLink; + } + + /** + * @param string $inviteLink + * @return void + */ + public function setInviteLink($inviteLink) + { + $this->inviteLink = $inviteLink; + } + + /** + * @return User + */ + public function getCreator() + { + return $this->creator; + } + + /** + * @param User $creator + * @return void + */ + public function setCreator($creator) + { + $this->creator = $creator; + } + + /** + * @return bool + */ + public function getCreatesJoinRequest() + { + return $this->createsJoinRequest; + } + + /** + * @param bool $createsJoinRequest + * @return void + */ + public function setCreatesJoinRequest($createsJoinRequest) + { + $this->createsJoinRequest = $createsJoinRequest; + } + + /** + * @return bool + */ + public function isPrimary() + { + return $this->isPrimary; + } + + /** + * @param bool $isPrimary + * @return void + */ + public function setIsPrimary($isPrimary) + { + $this->isPrimary = $isPrimary; + } + + /** + * @return bool + */ + public function isRevoked() + { + return $this->isRevoked; + } + + /** + * @param bool $isRevoked + * @return void + */ + public function setIsRevoked($isRevoked) + { + $this->isRevoked = $isRevoked; + } + + /** + * @return string|null + */ + public function getName() + { + return $this->name; + } + + /** + * @param string|null $name + * @return void + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return int|null + */ + public function getExpireDate() + { + return $this->expireDate; + } + + /** + * @param int|null $expireDate + * @return void + */ + public function setExpireDate($expireDate) + { + $this->expireDate = $expireDate; + } + + /** + * @return int|null + */ + public function getMemberLimit() + { + return $this->memberLimit; + } + + /** + * @param int|null $memberLimit + * @return void + */ + public function setMemberLimit($memberLimit) + { + $this->memberLimit = $memberLimit; + } + + /** + * @return int|null + */ + public function getPendingJoinRequestCount() + { + return $this->pendingJoinRequestCount; + } + + /** + * @param int|null $pendingJoinRequestCount + * @return void + */ + public function setPendingJoinRequestCount($pendingJoinRequestCount) + { + $this->pendingJoinRequestCount = $pendingJoinRequestCount; + } +} diff --git a/src/Types/ChatJoinRequest.php b/src/Types/ChatJoinRequest.php new file mode 100644 index 00000000..76b33718 --- /dev/null +++ b/src/Types/ChatJoinRequest.php @@ -0,0 +1,174 @@ + Chat::class, + 'from' => User::class, + 'user_chat_id' => true, + 'date' => true, + 'bio' => true, + 'invite_link' => ChatInviteLink::class, + ]; + + /** + * Chat to which the request was sent + * + * @var Chat + */ + protected $chat; + + /** + * User that sent the join request + * + * @var User + */ + protected $from; + + /** + * Identifier of a private chat with the user who sent the join request. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. The bot can use this identifier for 24 hours to send messages until the join request is processed, assuming no other administrator contacted the user. + * + * @var int + */ + protected $userChatId; + + /** + * Date the request was sent in Unix time + * + * @var int + */ + protected $date; + + /** + * Optional. Bio of the user. + * + * @var string|null + */ + protected $bio; + + /** + * Optional. Chat invite link that was used by the user to send the join request + * + * @var ChatInviteLink|null + */ + protected $inviteLink; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return User + */ + public function getFrom() + { + return $this->from; + } + + /** + * @param User $from + * @return void + */ + public function setFrom($from) + { + $this->from = $from; + } + + /** + * @return int + */ + public function getUserChatId() + { + return $this->userChatId; + } + + /** + * @param int $userChatId + * @return void + */ + public function setUserChatId($userChatId) + { + $this->userChatId = $userChatId; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + * @return void + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return string|null + */ + public function getBio() + { + return $this->bio; + } + + /** + * @param string|null $bio + * @return void + */ + public function setBio($bio) + { + $this->bio = $bio; + } + + /** + * @return ChatInviteLink|null + */ + public function getInviteLink() + { + return $this->inviteLink; + } + + /** + * @param ChatInviteLink|null $inviteLink + * @return void + */ + public function setInviteLink($inviteLink) + { + $this->inviteLink = $inviteLink; + } +} diff --git a/src/Types/ChatMemberUpdated.php b/src/Types/ChatMemberUpdated.php new file mode 100644 index 00000000..2c3ffb86 --- /dev/null +++ b/src/Types/ChatMemberUpdated.php @@ -0,0 +1,199 @@ + Chat::class, + 'from' => User::class, + 'date' => true, + 'old_chat_member' => ChatMember::class, + 'new_chat_member' => ChatMember::class, + 'invite_link' => ChatInviteLink::class, + 'via_chat_folder_invite_link' => true, + ]; + + /** + * Chat the user belongs to + * + * @var Chat + */ + protected $chat; + + /** + * Performer of the action, which resulted in the change + * + * @var User + */ + protected $from; + + /** + * Date the change was done in Unix time + * + * @var int + */ + protected $date; + + /** + * Previous information about the chat member + * + * @var ChatMember + */ + protected $oldChatMember; + + /** + * New information about the chat member + * + * @var ChatMember + */ + protected $newChatMember; + + /** + * Optional. Chat invite link, which was used by the user to join the chat; for joining by invite link events only. + * + * @var ChatInviteLink|null + */ + protected $inviteLink; + + /** + * Optional. True, if the user joined the chat via a chat folder invite link + * + * @var bool|null + */ + protected $viaChatFolderInviteLink; + + /** + * @return Chat + */ + public function getChat() + { + return $this->chat; + } + + /** + * @param Chat $chat + * @return void + */ + public function setChat($chat) + { + $this->chat = $chat; + } + + /** + * @return User + */ + public function getFrom() + { + return $this->from; + } + + /** + * @param User $from + * @return void + */ + public function setFrom($from) + { + $this->from = $from; + } + + /** + * @return int + */ + public function getDate() + { + return $this->date; + } + + /** + * @param int $date + * @return void + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return ChatMember + */ + public function getOldChatMember() + { + return $this->oldChatMember; + } + + /** + * @param ChatMember $oldChatMember + * @return void + */ + public function setOldChatMember($oldChatMember) + { + $this->oldChatMember = $oldChatMember; + } + + /** + * @return ChatMember + */ + public function getNewChatMember() + { + return $this->newChatMember; + } + + /** + * @param ChatMember $newChatMember + * @return void + */ + public function setNewChatMember($newChatMember) + { + $this->newChatMember = $newChatMember; + } + + /** + * @return ChatInviteLink|null + */ + public function getInviteLink() + { + return $this->inviteLink; + } + + /** + * @param ChatInviteLink|null $inviteLink + * @return void + */ + public function setInviteLink($inviteLink) + { + $this->inviteLink = $inviteLink; + } + + /** + * @return bool|null + */ + public function getViaChatFolderInviteLink() + { + return $this->viaChatFolderInviteLink; + } + + /** + * @param bool|null $viaChatFolderInviteLink + * @return void + */ + public function setViaChatFolderInviteLink($viaChatFolderInviteLink) + { + $this->viaChatFolderInviteLink = $viaChatFolderInviteLink; + } +} diff --git a/src/Types/Update.php b/src/Types/Update.php index 3d324d90..4138ed07 100644 --- a/src/Types/Update.php +++ b/src/Types/Update.php @@ -43,6 +43,9 @@ class Update extends BaseType implements TypeInterface 'pre_checkout_query' => PreCheckoutQuery::class, 'poll_answer' => PollAnswer::class, 'poll' => Poll::class, + 'my_chat_member' => ChatMemberUpdated::class, + 'chat_member' => ChatMemberUpdated::class, + 'chat_join_request' => ChatJoinRequest::class, ]; /** @@ -132,6 +135,30 @@ class Update extends BaseType implements TypeInterface */ protected $preCheckoutQuery; + /** + * Optional. The bot's chat member status was updated in a chat. For private chats, this update is received only + * when the bot is blocked or unblocked by the user. + * + * @var ChatMemberUpdated|null + */ + protected $myChatMember; + + /** + * Optional. A chat member's status was updated in a chat. The bot must be an administrator in the chat and must + * explicitly specify “chat_member” in the list of allowed_updates to receive these updates. + * + * @var ChatMemberUpdated|null + */ + protected $chatMember; + + /** + * Optional. A request to join the chat has been sent. The bot must have the can_invite_users administrator + * right in the chat to receive these updates. + * + * @var ChatJoinRequest|null + */ + protected $chatJoinRequest; + /** * @return int */ @@ -355,4 +382,55 @@ public function setPreCheckoutQuery($preCheckoutQuery) { $this->preCheckoutQuery = $preCheckoutQuery; } + + /** + * @return ChatMemberUpdated|null + */ + public function getMyChatMember() + { + return $this->myChatMember; + } + + /** + * @param ChatMemberUpdated|null $myChatMember + * @return void + */ + public function setMyChatMember($myChatMember) + { + $this->myChatMember = $myChatMember; + } + + /** + * @return ChatMemberUpdated|null + */ + public function getChatMember() + { + return $this->chatMember; + } + + /** + * @param ChatMemberUpdated|null $chatMember + * @return void + */ + public function setChatMember($chatMember) + { + $this->chatMember = $chatMember; + } + + /** + * @return ChatJoinRequest|null + */ + public function getChatJoinRequest() + { + return $this->chatJoinRequest; + } + + /** + * @param ChatJoinRequest|null $chatJoinRequest + * @return void + */ + public function setChatJoinRequest($chatJoinRequest) + { + $this->chatJoinRequest = $chatJoinRequest; + } } diff --git a/tests/Types/ChatInviteLinkTest.php b/tests/Types/ChatInviteLinkTest.php new file mode 100644 index 00000000..459d62bd --- /dev/null +++ b/tests/Types/ChatInviteLinkTest.php @@ -0,0 +1,74 @@ + 'invite_link', + 'creator' => UserTest::getMinResponse(), + 'creates_join_request' => true, + 'is_primary' => true, + 'is_revoked' => true, + ]; + } + + public static function getFullResponse() + { + return [ + 'invite_link' => 'invite_link', + 'creator' => UserTest::getMinResponse(), + 'creates_join_request' => true, + 'is_primary' => true, + 'is_revoked' => true, + 'name' => 'name', + 'expire_date' => 100500, + 'member_limit' => 10, + 'pending_join_request_count' => 10, + ]; + } + + /** + * @param ChatInviteLink $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals('invite_link', $item->getInviteLink()); + $this->assertEquals(UserTest::createMinInstance(), $item->getCreator()); + $this->assertTrue($item->getCreatesJoinRequest()); + $this->assertTrue($item->isPrimary()); + $this->assertTrue($item->isRevoked()); + $this->assertNull($item->getName()); + $this->assertNull($item->getExpireDate()); + $this->assertNull($item->getMemberLimit()); + $this->assertNull($item->getPendingJoinRequestCount()); + } + + /** + * @param ChatInviteLink $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals('invite_link', $item->getInviteLink()); + $this->assertEquals(UserTest::createMinInstance(), $item->getCreator()); + $this->assertTrue($item->getCreatesJoinRequest()); + $this->assertTrue($item->isPrimary()); + $this->assertTrue($item->isRevoked()); + $this->assertEquals('name', $item->getName()); + $this->assertEquals(100500, $item->getExpireDate()); + $this->assertEquals(10, $item->getMemberLimit()); + $this->assertEquals(10, $item->getPendingJoinRequestCount()); + } +} diff --git a/tests/Types/ChatJoinRequestTest.php b/tests/Types/ChatJoinRequestTest.php new file mode 100644 index 00000000..faaa52fe --- /dev/null +++ b/tests/Types/ChatJoinRequestTest.php @@ -0,0 +1,64 @@ + ChatTest::getMinResponse(), + 'from' => UserTest::getMinResponse(), + 'user_chat_id' => 10, + 'date' => 100500, + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getMinResponse(), + 'from' => UserTest::getMinResponse(), + 'user_chat_id' => 10, + 'date' => 100500, + 'bio' => 'bio', + 'invite_link' => ChatInviteLinkTest::getMinResponse(), + ]; + } + + /** + * @param ChatJoinRequest $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(10, $item->getUserChatId()); + $this->assertEquals(100500, $item->getDate()); + $this->assertNull($item->getBio()); + $this->assertNull($item->getInviteLink()); + } + + /** + * @param ChatJoinRequest $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(10, $item->getUserChatId()); + $this->assertEquals(100500, $item->getDate()); + $this->assertEquals('bio', $item->getBio()); + $this->assertEquals(ChatInviteLinkTest::createMinInstance(), $item->getInviteLink()); + } +} diff --git a/tests/Types/ChatMemberUpdatedTest.php b/tests/Types/ChatMemberUpdatedTest.php new file mode 100644 index 00000000..8f80f995 --- /dev/null +++ b/tests/Types/ChatMemberUpdatedTest.php @@ -0,0 +1,68 @@ + ChatTest::getMinResponse(), + 'from' => UserTest::getMinResponse(), + 'date' => 100500, + 'old_chat_member' => ChatMemberTest::getMinResponse(), + 'new_chat_member' => ChatMemberTest::getMinResponse(), + ]; + } + + public static function getFullResponse() + { + return [ + 'chat' => ChatTest::getMinResponse(), + 'from' => UserTest::getMinResponse(), + 'date' => 100500, + 'old_chat_member' => ChatMemberTest::getMinResponse(), + 'new_chat_member' => ChatMemberTest::getMinResponse(), + 'invite_link' => ChatInviteLinkTest::getMinResponse(), + 'via_chat_folder_invite_link' => true, + ]; + } + + /** + * @param ChatMemberUpdated $item + * @return void + */ + protected function assertMinItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(100500, $item->getDate()); + $this->assertEquals(ChatMemberTest::createMinInstance(), $item->getOldChatMember()); + $this->assertEquals(ChatMemberTest::createMinInstance(), $item->getNewChatMember()); + $this->assertNull($item->getInviteLink()); + $this->assertNull($item->getViaChatFolderInviteLink()); + } + + /** + * @param ChatMemberUpdated $item + * @return void + */ + protected function assertFullItem($item) + { + $this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); + $this->assertEquals(UserTest::createMinInstance(), $item->getFrom()); + $this->assertEquals(100500, $item->getDate()); + $this->assertEquals(ChatMemberTest::createMinInstance(), $item->getOldChatMember()); + $this->assertEquals(ChatMemberTest::createMinInstance(), $item->getNewChatMember()); + $this->assertEquals(ChatInviteLinkTest::createMinInstance(), $item->getInviteLink()); + $this->assertTrue($item->getViaChatFolderInviteLink()); + } +} diff --git a/tests/Types/UpdateTest.php b/tests/Types/UpdateTest.php index 21a7ffbc..73852b3d 100644 --- a/tests/Types/UpdateTest.php +++ b/tests/Types/UpdateTest.php @@ -38,11 +38,14 @@ public static function getFullResponse() 'pre_checkout_query' => PreCheckoutQueryTest::getMinResponse(), 'poll_answer' => PollAnswerTest::getMinResponse(), 'poll' => PollTest::getMinResponse(), + 'my_chat_member' => ChatMemberUpdatedTest::getMinResponse(), + 'chat_member' => ChatMemberUpdatedTest::getMinResponse(), + 'chat_join_request' => ChatJoinRequestTest::getMinResponse(), ]; } /** - * @param $item + * @param Update $item * @return void */ protected function assertMinItem($item) @@ -59,10 +62,13 @@ protected function assertMinItem($item) $this->assertNull($item->getPreCheckoutQuery()); $this->assertNull($item->getPollAnswer()); $this->assertNull($item->getPoll()); + $this->assertNull($item->getMyChatMember()); + $this->assertNull($item->getChatMember()); + $this->assertNull($item->getChatJoinRequest()); } /** - * @param $item + * @param Update $item * @return void */ protected function assertFullItem($item) @@ -79,5 +85,8 @@ protected function assertFullItem($item) $this->assertEquals(PreCheckoutQueryTest::createMinInstance(), $item->getPreCheckoutQuery()); $this->assertEquals(PollAnswerTest::createMinInstance(), $item->getPollAnswer()); $this->assertEquals(PollTest::createMinInstance(), $item->getPoll()); + $this->assertEquals(ChatMemberUpdatedTest::createMinInstance(), $item->getMyChatMember()); + $this->assertEquals(ChatMemberUpdatedTest::createMinInstance(), $item->getChatMember()); + $this->assertEquals(ChatJoinRequestTest::createMinInstance(), $item->getChatJoinRequest()); } }