From e1e484e04694f045dad59860b2332dc5ffe76adb Mon Sep 17 00:00:00 2001 From: Ruslan Efanov Date: Mon, 5 Jun 2023 14:10:11 +0300 Subject: [PATCH] add field quote for message --- src/Bot/Model/Entity/Message/Message.php | 20 +++++ src/Bot/Model/Entity/Message/Quote.php | 106 +++++++++++++++++++++++ tests/Bot/Tests/Model/MessageTest.php | 15 ++++ tests/Resources/messageWithQuote.json | 40 +++++++++ 4 files changed, 181 insertions(+) create mode 100644 src/Bot/Model/Entity/Message/Quote.php create mode 100644 tests/Resources/messageWithQuote.json diff --git a/src/Bot/Model/Entity/Message/Message.php b/src/Bot/Model/Entity/Message/Message.php index 5431b06..985c3cc 100644 --- a/src/Bot/Model/Entity/Message/Message.php +++ b/src/Bot/Model/Entity/Message/Message.php @@ -130,6 +130,14 @@ class Message implements ModelInterface */ private $note; + /** + * @var ?Quote $quote + * + * @Type("RetailCrm\Mg\Bot\Model\Entity\Message\Quote") + * @SkipWhenEmpty() + */ + private $quote; + /** * @var bool $isRead * @@ -403,6 +411,18 @@ class Message implements ModelInterface $this->note = $note; } + public function getQuote(): ?Quote + { + return $this->quote ?? null; + } + + public function setQuote(?Quote $quote): Message + { + $this->quote = $quote; + + return $this; + } + /** * @return bool|null */ diff --git a/src/Bot/Model/Entity/Message/Quote.php b/src/Bot/Model/Entity/Message/Quote.php new file mode 100644 index 0000000..52982f7 --- /dev/null +++ b/src/Bot/Model/Entity/Message/Quote.php @@ -0,0 +1,106 @@ +") + * @Accessor(getter="getTime",setter="setTime") + * @SkipWhenEmpty() + */ + private $time; + + /** + * @var string + * + * @Type("string") + */ + private $content; + + public function getId(): int + { + return $this->id; + } + + public function setId(int $id): Quote + { + $this->id = $id; + return $this; + } + + public function getType(): string + { + return $this->type; + } + + public function setType(string $type): Quote + { + $this->type = $type; + return $this; + } + + public function getFrom(): User + { + return $this->from; + } + + public function setFrom(User $from): Quote + { + $this->from = $from; + return $this; + } + + public function getTime(): DateTime + { + return $this->time; + } + + public function setTime(DateTime $time): Quote + { + $this->time = $time; + return $this; + } + + public function getContent(): string + { + return $this->content; + } + + public function setContent(string $content): Quote + { + $this->content = $content; + return $this; + } +} diff --git a/tests/Bot/Tests/Model/MessageTest.php b/tests/Bot/Tests/Model/MessageTest.php index 593d733..e327388 100644 --- a/tests/Bot/Tests/Model/MessageTest.php +++ b/tests/Bot/Tests/Model/MessageTest.php @@ -37,6 +37,21 @@ class MessageTest extends TestCase self::assertEquals($content, $result->getContent()); } + public function testDeserializationWithQuoute(): void + { + $json = file_get_contents(__DIR__ . '/../../../Resources/messageWithQuote.json'); + /** @var Message $message */ + $message = Serializer::deserialize($json, Message::class); + + self::assertEquals(3373, $message->getId()); + self::assertNotNull($message->getQuote()); + self::assertEquals("22144962", $message->getQuote()->getId()); + self::assertEquals("text", $message->getQuote()->getType()); + self::assertEquals("11111", $message->getQuote()->getFrom()->getId()); + self::assertEquals("Something content", $message->getQuote()->getContent()); + self::assertNotNull($message->getQuote()->getTime()); + } + public function testSerialization_NoContent(): void { $item = new Message(); diff --git a/tests/Resources/messageWithQuote.json b/tests/Resources/messageWithQuote.json new file mode 100644 index 0000000..9e09baa --- /dev/null +++ b/tests/Resources/messageWithQuote.json @@ -0,0 +1,40 @@ +{ + "id": 3373, + "time": "2023-04-26T21:22:19+03:00", + "type": "text", + "scope": "public", + "chat_id": 519717, + "is_read": false, + "is_edit": false, + "status": "seen", + "from": { + "id": 519896, + "external_id": "", + "type": "customer", + "avatar": "", + "name": "Иван Иванов", + "username": "Иван", + "first_name": "Иван", + "last_name": "Иванов" + }, + "content": "А можно при встрече и оплата картой.", + "quote": { + "id": 22144962, + "type": "text", + "from": { + "id": 11111, + "external_id": "116", + "type": "user", + "avatar": "", + "name": "Николай Замышляев", + "first_name": "Николай", + "last_name": "Замышляев", + "available": true + }, + "time": "2023-04-26T21:20:30+03:00", + "content": "Something content" + }, + "channel_id": 61, + "created_at": "2023-04-26T18:22:19.785679Z", + "updated_at": "2023-04-26T18:22:20.533114Z" +} \ No newline at end of file