mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-10-06 20:10:31 +00:00
Added BotRemovedFromChatUpdate & ChatTitleChangedUpdate & MessageChatCreatedUpdate & UserAddedToChatUpdate & UserRemovedFromChatUpdate
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Updates\BotRemovedFromChatUpdate;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
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)]
|
||||
final class BotRemovedFromChatUpdateTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArrayAndSerialized(): void
|
||||
{
|
||||
$data = [
|
||||
'update_type' => 'bot_removed',
|
||||
'timestamp' => 1679100000,
|
||||
'chat_id' => 123456,
|
||||
'user' => [
|
||||
'user_id' => 555,
|
||||
'first_name' => 'Admin',
|
||||
'username' => 'chat_admin',
|
||||
'is_bot' => false,
|
||||
'last_activity_time' => 1679000000,
|
||||
'last_name' => null,
|
||||
'description' => null,
|
||||
'avatar_url' => null,
|
||||
'full_avatar_url' => null,
|
||||
],
|
||||
'is_channel' => false,
|
||||
];
|
||||
|
||||
$update = BotRemovedFromChatUpdate::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(BotRemovedFromChatUpdate::class, $update);
|
||||
$this->assertSame(UpdateType::BotRemoved, $update->updateType);
|
||||
$this->assertSame(1679100000, $update->timestamp);
|
||||
$this->assertSame(123456, $update->chatId);
|
||||
$this->assertFalse($update->isChannel);
|
||||
$this->assertInstanceOf(User::class, $update->user);
|
||||
$this->assertSame(555, $update->user->userId);
|
||||
$this->assertEquals($data, $update->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function canBeCreatedForChannel(): void
|
||||
{
|
||||
$data = [
|
||||
'update_type' => 'bot_removed',
|
||||
'timestamp' => 1679100001,
|
||||
'chat_id' => 777888999,
|
||||
'user' => [
|
||||
'user_id' => 556,
|
||||
'first_name' => 'AdminChan',
|
||||
'is_bot' => false,
|
||||
'last_activity_time' => 1679000001,
|
||||
],
|
||||
'is_channel' => true,
|
||||
];
|
||||
|
||||
$update = BotRemovedFromChatUpdate::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(BotRemovedFromChatUpdate::class, $update);
|
||||
$this->assertTrue($update->isChannel);
|
||||
$this->assertSame(777888999, $update->chatId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Updates\ChatTitleChangedUpdate;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
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)]
|
||||
final class ChatTitleChangedUpdateTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArrayAndSerialized(): void
|
||||
{
|
||||
$data = [
|
||||
'update_type' => 'chat_title_changed',
|
||||
'timestamp' => 1680000000,
|
||||
'chat_id' => 12345,
|
||||
'user' => [
|
||||
'user_id' => 54321,
|
||||
'first_name' => 'John',
|
||||
'is_bot' => false,
|
||||
'last_activity_time' => 1679999999,
|
||||
'last_name' => null,
|
||||
'username' => null,
|
||||
'description' => null,
|
||||
'avatar_url' => null,
|
||||
'full_avatar_url' => null,
|
||||
],
|
||||
'title' => 'New Awesome Chat Title',
|
||||
];
|
||||
|
||||
$update = ChatTitleChangedUpdate::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(ChatTitleChangedUpdate::class, $update);
|
||||
$this->assertSame(UpdateType::ChatTitleChanged, $update->updateType);
|
||||
$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->assertSame(54321, $update->user->userId);
|
||||
$this->assertEquals($data, $update->toArray());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Chat;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Image;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Updates\MessageChatCreatedUpdate;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(MessageChatCreatedUpdate::class)]
|
||||
#[UsesClass(Chat::class)]
|
||||
#[UsesClass(User::class)]
|
||||
#[UsesClass(Image::class)]
|
||||
final class MessageChatCreatedUpdateTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedWithAllData(): void
|
||||
{
|
||||
$data = [
|
||||
'update_type' => 'message_chat_created',
|
||||
'timestamp' => 1683000000,
|
||||
'chat' => [
|
||||
'chat_id' => 12345,
|
||||
'type' => 'chat',
|
||||
'status' => 'active',
|
||||
'last_event_time' => 1683000000,
|
||||
'participants_count' => 1,
|
||||
'is_public' => false,
|
||||
'title' => 'New Discussion',
|
||||
],
|
||||
'message_id' => 'mid.original.with.button',
|
||||
'start_payload' => 'payload_from_chat_button',
|
||||
];
|
||||
|
||||
$update = MessageChatCreatedUpdate::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(MessageChatCreatedUpdate::class, $update);
|
||||
$this->assertSame(UpdateType::MessageChatCreated, $update->updateType);
|
||||
$this->assertInstanceOf(Chat::class, $update->chat);
|
||||
$this->assertSame(12345, $update->chat->chatId);
|
||||
$this->assertSame('mid.original.with.button', $update->messageId);
|
||||
$this->assertSame('payload_from_chat_button', $update->startPayload);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function canBeCreatedWithNullStartPayload(): void
|
||||
{
|
||||
$data = [
|
||||
'update_type' => 'message_chat_created',
|
||||
'timestamp' => 1683000001,
|
||||
'chat' => [
|
||||
'chat_id' => 54321,
|
||||
'type' => 'chat',
|
||||
'status' => 'active',
|
||||
'last_event_time' => 1683000001,
|
||||
'participants_count' => 1,
|
||||
'is_public' => false,
|
||||
'title' => 'Another Discussion',
|
||||
],
|
||||
'message_id' => 'mid.another.message',
|
||||
'start_payload' => null,
|
||||
];
|
||||
|
||||
$update = MessageChatCreatedUpdate::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(MessageChatCreatedUpdate::class, $update);
|
||||
$this->assertNull($update->startPayload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Updates\UserAddedToChatUpdate;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
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)]
|
||||
final class UserAddedToChatUpdateTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedWhenInvitedByUser(): void
|
||||
{
|
||||
$data = [
|
||||
'update_type' => 'user_added',
|
||||
'timestamp' => 1681000000,
|
||||
'chat_id' => 12345,
|
||||
'user' => [
|
||||
'user_id' => 101,
|
||||
'first_name' => 'New',
|
||||
'last_name' => 'Member',
|
||||
'is_bot' => false,
|
||||
'last_activity_time' => 1680000000,
|
||||
'username' => null,
|
||||
'description' => null,
|
||||
'avatar_url' => null,
|
||||
'full_avatar_url' => null,
|
||||
],
|
||||
'inviter_id' => 202,
|
||||
'is_channel' => false,
|
||||
];
|
||||
|
||||
$update = UserAddedToChatUpdate::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(UserAddedToChatUpdate::class, $update);
|
||||
$this->assertSame(UpdateType::UserAdded, $update->updateType);
|
||||
$this->assertSame(12345, $update->chatId);
|
||||
$this->assertSame(202, $update->inviterId);
|
||||
$this->assertFalse($update->isChannel);
|
||||
$this->assertInstanceOf(User::class, $update->user);
|
||||
$this->assertSame(101, $update->user->userId);
|
||||
$this->assertEquals($data, $update->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function canBeCreatedWhenJoinedByLink(): void
|
||||
{
|
||||
$data = [
|
||||
'update_type' => 'user_added',
|
||||
'timestamp' => 1681000001,
|
||||
'chat_id' => 54321,
|
||||
'user' => [
|
||||
'user_id' => 303,
|
||||
'first_name' => 'Link',
|
||||
'last_name' => 'Joiner',
|
||||
'is_bot' => false,
|
||||
'last_activity_time' => 1680000001,
|
||||
'username' => null,
|
||||
'description' => null,
|
||||
'avatar_url' => null,
|
||||
'full_avatar_url' => null,
|
||||
],
|
||||
'inviter_id' => null,
|
||||
'is_channel' => true,
|
||||
];
|
||||
|
||||
$update = UserAddedToChatUpdate::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(UserAddedToChatUpdate::class, $update);
|
||||
$this->assertNull($update->inviterId);
|
||||
$this->assertTrue($update->isChannel);
|
||||
$this->assertSame(303, $update->user->userId);
|
||||
$this->assertEquals($data, $update->toArray());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Updates\UserRemovedFromChatUpdate;
|
||||
use BushlanovDev\MaxMessengerBot\Models\User;
|
||||
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)]
|
||||
final class UserRemovedFromChatUpdateTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedWhenRemovedByAdmin(): void
|
||||
{
|
||||
$data = [
|
||||
'update_type' => 'user_removed',
|
||||
'timestamp' => 1682000000,
|
||||
'chat_id' => 98765,
|
||||
'user' => [
|
||||
'user_id' => 111,
|
||||
'first_name' => 'Removed',
|
||||
'last_name' => 'User',
|
||||
'is_bot' => false,
|
||||
'last_activity_time' => 1681000000,
|
||||
'username' => null,
|
||||
'description' => null,
|
||||
'avatar_url' => null,
|
||||
'full_avatar_url' => null,
|
||||
],
|
||||
'admin_id' => 222,
|
||||
'is_channel' => false,
|
||||
];
|
||||
|
||||
$update = UserRemovedFromChatUpdate::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(UserRemovedFromChatUpdate::class, $update);
|
||||
$this->assertSame(UpdateType::UserRemoved, $update->updateType);
|
||||
$this->assertSame(98765, $update->chatId);
|
||||
$this->assertSame(222, $update->adminId);
|
||||
$this->assertFalse($update->isChannel);
|
||||
$this->assertInstanceOf(User::class, $update->user);
|
||||
$this->assertSame(111, $update->user->userId);
|
||||
$this->assertEquals($data, $update->toArray());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function canBeCreatedWhenUserLeft(): void
|
||||
{
|
||||
$data = [
|
||||
'update_type' => 'user_removed',
|
||||
'timestamp' => 1682000001,
|
||||
'chat_id' => 112233,
|
||||
'user' => [
|
||||
'user_id' => 444,
|
||||
'first_name' => 'Self',
|
||||
'last_name' => 'Remover',
|
||||
'is_bot' => false,
|
||||
'last_activity_time' => 1681000001,
|
||||
'username' => null,
|
||||
'description' => null,
|
||||
'avatar_url' => null,
|
||||
'full_avatar_url' => null,
|
||||
],
|
||||
'admin_id' => null,
|
||||
'is_channel' => true,
|
||||
];
|
||||
|
||||
$update = UserRemovedFromChatUpdate::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(UserRemovedFromChatUpdate::class, $update);
|
||||
$this->assertNull($update->adminId);
|
||||
$this->assertTrue($update->isChannel);
|
||||
$this->assertSame(444, $update->user->userId);
|
||||
$this->assertEquals($data, $update->toArray());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user