From 40742ddc60227457ce2a26374f38d6a67fb23747 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 20 Mar 2026 22:55:36 +0300 Subject: [PATCH] Removed deprecated ReplyKeyboardAttachment #27 --- src/Enums/AttachmentType.php | 1 - src/ModelFactory.php | 14 +-- .../ReplyKeyboardAttachmentRequestPayload.php | 22 ----- .../Attachments/ReplyKeyboardAttachment.php | 19 ---- .../ReplyKeyboardAttachmentRequest.php | 28 ------ tests/ModelFactoryTest.php | 22 ----- ...lyKeyboardAttachmentRequestPayloadTest.php | 99 ------------------- .../ReplyKeyboardAttachmentTest.php | 43 -------- .../ReplyKeyboardAttachmentRequestTest.php | 59 ----------- 9 files changed, 2 insertions(+), 305 deletions(-) delete mode 100644 src/Models/Attachments/Payloads/ReplyKeyboardAttachmentRequestPayload.php delete mode 100644 src/Models/Attachments/ReplyKeyboardAttachment.php delete mode 100644 src/Models/Attachments/Requests/ReplyKeyboardAttachmentRequest.php delete mode 100644 tests/Models/Attachments/Payloads/ReplyKeyboardAttachmentRequestPayloadTest.php delete mode 100644 tests/Models/Attachments/ReplyKeyboardAttachmentTest.php delete mode 100644 tests/Models/Attachments/Requests/ReplyKeyboardAttachmentRequestTest.php diff --git a/src/Enums/AttachmentType.php b/src/Enums/AttachmentType.php index 4e3d35d..af81056 100644 --- a/src/Enums/AttachmentType.php +++ b/src/Enums/AttachmentType.php @@ -13,7 +13,6 @@ enum AttachmentType: string case Sticker = 'sticker'; case Contact = 'contact'; case InlineKeyboard = 'inline_keyboard'; - case ReplyKeyboard = 'reply_keyboard'; case Location = 'location'; case Share = 'share'; case Data = 'data'; diff --git a/src/ModelFactory.php b/src/ModelFactory.php index 3e8f482..ce8a46a 100644 --- a/src/ModelFactory.php +++ b/src/ModelFactory.php @@ -29,7 +29,6 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\FileAttachment; use BushlanovDev\MaxMessengerBot\Models\Attachments\InlineKeyboardAttachment; use BushlanovDev\MaxMessengerBot\Models\Attachments\LocationAttachment; use BushlanovDev\MaxMessengerBot\Models\Attachments\PhotoAttachment; -use BushlanovDev\MaxMessengerBot\Models\Attachments\ReplyKeyboardAttachment; use BushlanovDev\MaxMessengerBot\Models\Attachments\ShareAttachment; use BushlanovDev\MaxMessengerBot\Models\Attachments\StickerAttachment; use BushlanovDev\MaxMessengerBot\Models\Attachments\VideoAttachment; @@ -242,14 +241,6 @@ readonly class ModelFactory public function createAttachment(array $data): AbstractAttachment { $attachmentType = AttachmentType::tryFrom($data['type'] ?? ''); - if ($attachmentType === AttachmentType::ReplyKeyboard - && isset($data['buttons']) && is_array($data['buttons'])) { - $data['buttons'] = array_map( - fn($rowOfButtons) => array_map([$this, 'createReplyButton'], $rowOfButtons), - $data['buttons'], - ); - } - if ($attachmentType === AttachmentType::InlineKeyboard && isset($data['payload']['buttons']) && is_array($data['payload']['buttons'])) { $data['payload']['buttons'] = array_map( @@ -259,8 +250,6 @@ readonly class ModelFactory } return match ($attachmentType) { - AttachmentType::Data => DataAttachment::fromArray($data), - AttachmentType::Share => ShareAttachment::fromArray($data), AttachmentType::Image => PhotoAttachment::fromArray($data), AttachmentType::Video => VideoAttachment::fromArray($data), AttachmentType::Audio => AudioAttachment::fromArray($data), @@ -268,8 +257,9 @@ readonly class ModelFactory AttachmentType::Sticker => StickerAttachment::fromArray($data), AttachmentType::Contact => ContactAttachment::fromArray($data), AttachmentType::InlineKeyboard => InlineKeyboardAttachment::fromArray($data), - AttachmentType::ReplyKeyboard => ReplyKeyboardAttachment::fromArray($data), AttachmentType::Location => LocationAttachment::fromArray($data), + AttachmentType::Share => ShareAttachment::fromArray($data), + AttachmentType::Data => DataAttachment::fromArray($data), default => throw new LogicException('Unknown or unsupported attachment type: ' . ($data['type'] ?? 'none')), }; } diff --git a/src/Models/Attachments/Payloads/ReplyKeyboardAttachmentRequestPayload.php b/src/Models/Attachments/Payloads/ReplyKeyboardAttachmentRequestPayload.php deleted file mode 100644 index ed594dd..0000000 --- a/src/Models/Attachments/Payloads/ReplyKeyboardAttachmentRequestPayload.php +++ /dev/null @@ -1,22 +0,0 @@ -factory->createMarkupElement(['type' => 'brand_new_unsupported_type']); } - #[Test] - public function createAttachmentCorrectlyHydratesReplyKeyboard(): void - { - $data = [ - 'type' => 'reply_keyboard', - 'buttons' => [ - [['type' => 'message', 'text' => 'Hello']], - [['type' => 'user_contact', 'text' => 'My Contact']] - ] - ]; - - $attachment = $this->factory->createAttachment($data); - - $this->assertInstanceOf(ReplyKeyboardAttachment::class, $attachment); - $this->assertCount(2, $attachment->buttons); - $this->assertInstanceOf(SendMessageButton::class, $attachment->buttons[0][0]); - $this->assertInstanceOf(SendContactButton::class, $attachment->buttons[1][0]); - $this->assertSame('My Contact', $attachment->buttons[1][0]->text); - } - #[Test] public function createReplyButtonThrowsExceptionForUnknownType(): void { diff --git a/tests/Models/Attachments/Payloads/ReplyKeyboardAttachmentRequestPayloadTest.php b/tests/Models/Attachments/Payloads/ReplyKeyboardAttachmentRequestPayloadTest.php deleted file mode 100644 index 65c90a8..0000000 --- a/tests/Models/Attachments/Payloads/ReplyKeyboardAttachmentRequestPayloadTest.php +++ /dev/null @@ -1,99 +0,0 @@ - [ - [ - [ - 'type' => 'message', - 'text' => 'Help', - 'payload' => null, - 'intent' => 'default', - ], - ], - [ - [ - 'type' => 'user_contact', - 'text' => 'Share Contact', - ], - ], - ], - 'direct' => false, - 'direct_user_id' => null, - ]; - - $this->assertEquals($expected, $payload->toArray()); - } - - #[Test] - public function toArrayWithAllParameters(): void - { - $buttons = [ - [new SendMessageButton('Confirm', 'confirm-action', Intent::Positive)], - ]; - - $payload = new ReplyKeyboardAttachmentRequestPayload( - buttons: $buttons, - direct: true, - directUserId: 987654321, - ); - - $expected = [ - 'buttons' => [ - [ - [ - 'type' => 'message', - 'text' => 'Confirm', - 'payload' => 'confirm-action', - 'intent' => 'positive', - ], - ], - ], - 'direct' => true, - 'direct_user_id' => 987654321, - ]; - - $this->assertEquals($expected, $payload->toArray()); - } - - #[Test] - public function toArrayWithEmptyButtons(): void - { - $payload = new ReplyKeyboardAttachmentRequestPayload(buttons: []); - - $expected = [ - 'buttons' => [], - 'direct' => false, - 'direct_user_id' => null, - ]; - - $this->assertEquals($expected, $payload->toArray()); - } -} diff --git a/tests/Models/Attachments/ReplyKeyboardAttachmentTest.php b/tests/Models/Attachments/ReplyKeyboardAttachmentTest.php deleted file mode 100644 index e894068..0000000 --- a/tests/Models/Attachments/ReplyKeyboardAttachmentTest.php +++ /dev/null @@ -1,43 +0,0 @@ - 'reply_keyboard', - 'buttons' => [ - [['type' => 'message', 'text' => 'Hello']], - [['type' => 'user_contact', 'text' => 'My Contact']] - ] - ]; - - $factory = new ModelFactory(); - $attachment = $factory->createAttachment($data); - - $this->assertInstanceOf(ReplyKeyboardAttachment::class, $attachment); - $this->assertCount(2, $attachment->buttons); - $this->assertInstanceOf(SendContactButton::class, $attachment->buttons[1][0]); - $this->assertSame('My Contact', $attachment->buttons[1][0]->text); - } -} diff --git a/tests/Models/Attachments/Requests/ReplyKeyboardAttachmentRequestTest.php b/tests/Models/Attachments/Requests/ReplyKeyboardAttachmentRequestTest.php deleted file mode 100644 index 9d3b788..0000000 --- a/tests/Models/Attachments/Requests/ReplyKeyboardAttachmentRequestTest.php +++ /dev/null @@ -1,59 +0,0 @@ - 'reply_keyboard', - 'payload' => [ - 'buttons' => [ - [ - [ - 'type' => 'message', - 'text' => 'Help', - 'payload' => 'help_payload', - 'intent' => 'positive', - ], - ], - [ - [ - 'type' => 'user_contact', - 'text' => 'Share Contact', - ], - ], - ], - 'direct' => true, - 'direct_user_id' => null, - ], - ]; - - $this->assertEquals($expectedArray, $request->toArray()); - } -}