mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-10-09 05:17:31 +00:00
Removed deprecated DataAttachment
This commit is contained in:
@@ -15,5 +15,4 @@ enum AttachmentType: string
|
|||||||
case InlineKeyboard = 'inline_keyboard';
|
case InlineKeyboard = 'inline_keyboard';
|
||||||
case Location = 'location';
|
case Location = 'location';
|
||||||
case Share = 'share';
|
case Share = 'share';
|
||||||
case Data = 'data';
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactBut
|
|||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendGeoLocationButton;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendGeoLocationButton;
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\ContactAttachment;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\ContactAttachment;
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\DataAttachment;
|
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\FileAttachment;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\FileAttachment;
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\InlineKeyboardAttachment;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\InlineKeyboardAttachment;
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\LocationAttachment;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\LocationAttachment;
|
||||||
@@ -259,7 +258,6 @@ readonly class ModelFactory
|
|||||||
AttachmentType::InlineKeyboard => InlineKeyboardAttachment::fromArray($data),
|
AttachmentType::InlineKeyboard => InlineKeyboardAttachment::fromArray($data),
|
||||||
AttachmentType::Location => LocationAttachment::fromArray($data),
|
AttachmentType::Location => LocationAttachment::fromArray($data),
|
||||||
AttachmentType::Share => ShareAttachment::fromArray($data),
|
AttachmentType::Share => ShareAttachment::fromArray($data),
|
||||||
AttachmentType::Data => DataAttachment::fromArray($data),
|
|
||||||
default => throw new LogicException('Unknown or unsupported attachment type: ' . ($data['type'] ?? 'none')),
|
default => throw new LogicException('Unknown or unsupported attachment type: ' . ($data['type'] ?? 'none')),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace BushlanovDev\MaxMessengerBot\Models\Attachments;
|
|
||||||
|
|
||||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents an attachment containing a payload from a SendMessageButton.
|
|
||||||
*/
|
|
||||||
final readonly class DataAttachment extends AbstractAttachment
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param string $data The payload from the button.
|
|
||||||
*/
|
|
||||||
public function __construct(public string $data)
|
|
||||||
{
|
|
||||||
parent::__construct(AttachmentType::Data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,7 +18,6 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestGeoLoc
|
|||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactButton;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendContactButton;
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\SendMessageButton;
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\DataAttachment;
|
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\InlineKeyboardAttachment;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\InlineKeyboardAttachment;
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\LocationAttachment;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\LocationAttachment;
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\KeyboardPayload;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\KeyboardPayload;
|
||||||
@@ -84,7 +83,6 @@ use Psr\Log\LoggerInterface;
|
|||||||
#[UsesClass(PhotoAttachmentRequestPayload::class)]
|
#[UsesClass(PhotoAttachmentRequestPayload::class)]
|
||||||
#[UsesClass(VideoUrls::class)]
|
#[UsesClass(VideoUrls::class)]
|
||||||
#[UsesClass(AbstractAttachment::class)]
|
#[UsesClass(AbstractAttachment::class)]
|
||||||
#[UsesClass(DataAttachment::class)]
|
|
||||||
#[UsesClass(ShareAttachment::class)]
|
#[UsesClass(ShareAttachment::class)]
|
||||||
#[UsesClass(ShareAttachmentRequestPayload::class)]
|
#[UsesClass(ShareAttachmentRequestPayload::class)]
|
||||||
#[UsesClass(LinkMarkup::class)]
|
#[UsesClass(LinkMarkup::class)]
|
||||||
@@ -591,7 +589,6 @@ final class ModelFactoryTest extends TestCase
|
|||||||
'seq' => 102,
|
'seq' => 102,
|
||||||
'text' => 'Message with data attachment',
|
'text' => 'Message with data attachment',
|
||||||
'attachments' => [
|
'attachments' => [
|
||||||
['type' => 'data', 'data' => 'payload_from_reply_button'],
|
|
||||||
[
|
[
|
||||||
'type' => 'share',
|
'type' => 'share',
|
||||||
'payload' => ['url' => 'http://a.com'],
|
'payload' => ['url' => 'http://a.com'],
|
||||||
@@ -613,16 +610,13 @@ final class ModelFactoryTest extends TestCase
|
|||||||
$this->assertInstanceOf(Message::class, $message);
|
$this->assertInstanceOf(Message::class, $message);
|
||||||
$this->assertInstanceOf(MessageBody::class, $message->body);
|
$this->assertInstanceOf(MessageBody::class, $message->body);
|
||||||
$this->assertIsArray($attachments);
|
$this->assertIsArray($attachments);
|
||||||
$this->assertCount(3, $attachments);
|
$this->assertCount(2, $attachments);
|
||||||
|
|
||||||
$this->assertInstanceOf(DataAttachment::class, $attachments[0]);
|
$this->assertInstanceOf(ShareAttachment::class, $message->body->attachments[0]);
|
||||||
$this->assertSame('payload_from_reply_button', $attachments[0]->data);
|
$this->assertSame('Test Share', $attachments[0]->title);
|
||||||
|
|
||||||
$this->assertInstanceOf(ShareAttachment::class, $message->body->attachments[1]);
|
$this->assertInstanceOf(PhotoAttachment::class, $attachments[1]);
|
||||||
$this->assertSame('Test Share', $attachments[1]->title);
|
$this->assertSame(1, $attachments[1]->payload->photoId);
|
||||||
|
|
||||||
$this->assertInstanceOf(PhotoAttachment::class, $attachments[2]);
|
|
||||||
$this->assertSame(1, $attachments[2]->payload->photoId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
@@ -747,14 +741,6 @@ final class ModelFactoryTest extends TestCase
|
|||||||
public static function attachmentTypeProvider(): array
|
public static function attachmentTypeProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'Data Attachment' => [
|
|
||||||
['type' => 'data', 'data' => 'test_payload'],
|
|
||||||
DataAttachment::class,
|
|
||||||
function (TestCase $test, DataAttachment $attachment) {
|
|
||||||
$test->assertSame('test_payload', $attachment->data);
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
'Location Attachment' => [
|
'Location Attachment' => [
|
||||||
['type' => 'location', 'latitude' => 55.751244, 'longitude' => 37.618423],
|
['type' => 'location', 'latitude' => 55.751244, 'longitude' => 37.618423],
|
||||||
LocationAttachment::class,
|
LocationAttachment::class,
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments;
|
|
||||||
|
|
||||||
use BushlanovDev\MaxMessengerBot\Enums\AttachmentType;
|
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\AbstractAttachment;
|
|
||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\DataAttachment;
|
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
|
||||||
use PHPUnit\Framework\Attributes\Test;
|
|
||||||
use PHPUnit\Framework\Attributes\UsesClass;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
#[CoversClass(DataAttachment::class)]
|
|
||||||
#[UsesClass(AbstractAttachment::class)]
|
|
||||||
final class DataAttachmentTest extends TestCase
|
|
||||||
{
|
|
||||||
#[Test]
|
|
||||||
public function canBeCreatedAndSerialized(): void
|
|
||||||
{
|
|
||||||
$attachment = new DataAttachment('some_payload_from_button');
|
|
||||||
|
|
||||||
$this->assertSame(AttachmentType::Data, $attachment->type);
|
|
||||||
$this->assertSame('some_payload_from_button', $attachment->data);
|
|
||||||
|
|
||||||
$expectedArray = [
|
|
||||||
'type' => 'data',
|
|
||||||
'data' => 'some_payload_from_button',
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->assertEquals($expectedArray, $attachment->toArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Test]
|
|
||||||
public function canBeCreatedFromArray(): void
|
|
||||||
{
|
|
||||||
$data = [
|
|
||||||
'type' => 'data',
|
|
||||||
'data' => 'payload123',
|
|
||||||
];
|
|
||||||
|
|
||||||
$attachment = DataAttachment::fromArray($data);
|
|
||||||
|
|
||||||
$this->assertInstanceOf(DataAttachment::class, $attachment);
|
|
||||||
$this->assertSame(AttachmentType::Data, $attachment->type);
|
|
||||||
$this->assertSame('payload123', $attachment->data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user