From a94043399623eeb95a0a37712f9be8ba5912e86a Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 28 Jun 2024 21:54:07 +0300 Subject: [PATCH 1/7] Fix `InputPollOption` --- src/Type/InputPollOption.php | 4 ++-- tests/Type/InputPollOptionTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Type/InputPollOption.php b/src/Type/InputPollOption.php index 438795d..b75d6ec 100644 --- a/src/Type/InputPollOption.php +++ b/src/Type/InputPollOption.php @@ -24,8 +24,8 @@ public function toRequestArray(): array return array_filter( [ 'text' => $this->text, - 'parse_mode' => $this->textParseMode, - 'entities' => $this->textEntities === null + 'text_parse_mode' => $this->textParseMode, + 'text_entities' => $this->textEntities === null ? null : array_map( static fn(MessageEntity $entity) => $entity->toRequestArray(), diff --git a/tests/Type/InputPollOptionTest.php b/tests/Type/InputPollOptionTest.php index ff708f1..7bc6b06 100644 --- a/tests/Type/InputPollOptionTest.php +++ b/tests/Type/InputPollOptionTest.php @@ -33,8 +33,8 @@ public function testFilled(): void $this->assertSame( [ 'text' => 'test', - 'parse_mode' => 'MarkdownV2', - 'entities' => [$messageEntity->toRequestArray()], + 'text_parse_mode' => 'MarkdownV2', + 'text_entities' => [$messageEntity->toRequestArray()], ], $option->toRequestArray(), ); From 8fd76f62fe670b5c1c00d26fe57252881894092f Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 28 Jun 2024 22:03:03 +0300 Subject: [PATCH 2/7] Add `LabeledPrice` type --- src/Type/Payment/LabeledPrice.php | 25 ++++++++++++++++++++++++ tests/Type/Payment/LabeledPriceTest.php | 26 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/Type/Payment/LabeledPrice.php create mode 100644 tests/Type/Payment/LabeledPriceTest.php diff --git a/src/Type/Payment/LabeledPrice.php b/src/Type/Payment/LabeledPrice.php new file mode 100644 index 0000000..ddcd7dd --- /dev/null +++ b/src/Type/Payment/LabeledPrice.php @@ -0,0 +1,25 @@ + $this->label, + 'amount' => $this->amount, + ]; + } +} diff --git a/tests/Type/Payment/LabeledPriceTest.php b/tests/Type/Payment/LabeledPriceTest.php new file mode 100644 index 0000000..043e377 --- /dev/null +++ b/tests/Type/Payment/LabeledPriceTest.php @@ -0,0 +1,26 @@ +assertSame('Red good', $type->label); + $this->assertSame(10, $type->amount); + $this->assertSame( + [ + 'label' => 'Red good', + 'amount' => 10, + ], + $type->toRequestArray(), + ); + } +} From f895ba35beba9b28f2f2ca9df8578e4daaba9cdb Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 28 Jun 2024 22:21:51 +0300 Subject: [PATCH 3/7] Add `InputMessageContent` types --- .../Inline/InputContactMessageContent.php | 32 +++++ .../Inline/InputInvoiceMessageContent.php | 73 ++++++++++ .../Inline/InputLocationMessageContent.php | 36 +++++ src/Type/Inline/InputMessageContent.php | 13 ++ src/Type/Inline/InputTextMessageContent.php | 41 ++++++ src/Type/Inline/InputVenueMessageContent.php | 40 ++++++ .../Inline/InputContactMessageContentTest.php | 49 +++++++ .../Inline/InputInvoiceMessageContentTest.php | 130 ++++++++++++++++++ .../InputLocationMessageContentTest.php | 53 +++++++ .../Inline/InputTextMessageContentTest.php | 52 +++++++ .../Inline/InputVenueMessageContentTest.php | 61 ++++++++ 11 files changed, 580 insertions(+) create mode 100644 src/Type/Inline/InputContactMessageContent.php create mode 100644 src/Type/Inline/InputInvoiceMessageContent.php create mode 100644 src/Type/Inline/InputLocationMessageContent.php create mode 100644 src/Type/Inline/InputMessageContent.php create mode 100644 src/Type/Inline/InputTextMessageContent.php create mode 100644 src/Type/Inline/InputVenueMessageContent.php create mode 100644 tests/Type/Inline/InputContactMessageContentTest.php create mode 100644 tests/Type/Inline/InputInvoiceMessageContentTest.php create mode 100644 tests/Type/Inline/InputLocationMessageContentTest.php create mode 100644 tests/Type/Inline/InputTextMessageContentTest.php create mode 100644 tests/Type/Inline/InputVenueMessageContentTest.php diff --git a/src/Type/Inline/InputContactMessageContent.php b/src/Type/Inline/InputContactMessageContent.php new file mode 100644 index 0000000..f873653 --- /dev/null +++ b/src/Type/Inline/InputContactMessageContent.php @@ -0,0 +1,32 @@ + $this->phoneNumber, + 'first_name' => $this->firstName, + 'last_name' => $this->lastName, + 'vcard' => $this->vcard, + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InputInvoiceMessageContent.php b/src/Type/Inline/InputInvoiceMessageContent.php new file mode 100644 index 0000000..36b75b6 --- /dev/null +++ b/src/Type/Inline/InputInvoiceMessageContent.php @@ -0,0 +1,73 @@ + $this->title, + 'description' => $this->description, + 'payload' => $this->payload, + 'provider_token' => $this->providerToken, + 'currency' => $this->currency, + 'prices' => array_map( + static fn(LabeledPrice $price) => $price->toRequestArray(), + $this->prices, + ), + 'max_tip_amount' => $this->maxTipAmount, + 'suggested_tip_amounts' => $this->suggestedTipAmounts, + 'provider_data' => $this->providerData, + 'photo_url' => $this->photoUrl, + 'photo_size' => $this->photoSize, + 'photo_width' => $this->photoWidth, + 'photo_height' => $this->photoHeight, + 'need_name' => $this->needName, + 'need_phone_number' => $this->needPhoneNumber, + 'need_email' => $this->needEmail, + 'need_shipping_address' => $this->needShippingAddress, + 'send_phone_number_to_provider' => $this->sendPhoneNumberToProvider, + 'send_email_to_provider' => $this->sendEmailToProvider, + 'is_flexible' => $this->isFlexible, + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InputLocationMessageContent.php b/src/Type/Inline/InputLocationMessageContent.php new file mode 100644 index 0000000..72abfb9 --- /dev/null +++ b/src/Type/Inline/InputLocationMessageContent.php @@ -0,0 +1,36 @@ + $this->latitude, + 'longitude' => $this->longitude, + 'horizontal_accuracy' => $this->horizontalAccuracy, + 'live_period' => $this->livePeriod, + 'heading' => $this->heading, + 'proximity_alert_radius' => $this->proximityAlertRadius, + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InputMessageContent.php b/src/Type/Inline/InputMessageContent.php new file mode 100644 index 0000000..463aca3 --- /dev/null +++ b/src/Type/Inline/InputMessageContent.php @@ -0,0 +1,13 @@ + $this->messageText, + 'parse_mode' => $this->parseMode, + 'entities' => $this->entities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->entities, + ), + 'link_preview_options' => $this->linkPreviewOptions?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InputVenueMessageContent.php b/src/Type/Inline/InputVenueMessageContent.php new file mode 100644 index 0000000..fabb64c --- /dev/null +++ b/src/Type/Inline/InputVenueMessageContent.php @@ -0,0 +1,40 @@ + $this->latitude, + 'longitude' => $this->longitude, + 'title' => $this->title, + 'address' => $this->address, + 'foursquare_id' => $this->foursquareId, + 'foursquare_type' => $this->foursquareType, + 'google_place_id' => $this->googlePlaceId, + 'google_place_type' => $this->googlePlaceType, + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/tests/Type/Inline/InputContactMessageContentTest.php b/tests/Type/Inline/InputContactMessageContentTest.php new file mode 100644 index 0000000..1e2b2eb --- /dev/null +++ b/tests/Type/Inline/InputContactMessageContentTest.php @@ -0,0 +1,49 @@ +assertSame('+70001234567', $type->phoneNumber); + $this->assertSame('John', $type->firstName); + $this->assertNull($type->lastName); + $this->assertNull($type->vcard); + + $this->assertSame( + [ + 'phone_number' => '+70001234567', + 'first_name' => 'John', + ], + $type->toRequestArray(), + ); + } + + public function testFull(): void + { + $type = new InputContactMessageContent('+70001234567', 'John', 'Doe', 'vcard!'); + + $this->assertSame('+70001234567', $type->phoneNumber); + $this->assertSame('John', $type->firstName); + $this->assertSame('Doe', $type->lastName); + $this->assertSame('vcard!', $type->vcard); + + $this->assertSame( + [ + 'phone_number' => '+70001234567', + 'first_name' => 'John', + 'last_name' => 'Doe', + 'vcard' => 'vcard!', + ], + $type->toRequestArray(), + ); + } +} diff --git a/tests/Type/Inline/InputInvoiceMessageContentTest.php b/tests/Type/Inline/InputInvoiceMessageContentTest.php new file mode 100644 index 0000000..5becb50 --- /dev/null +++ b/tests/Type/Inline/InputInvoiceMessageContentTest.php @@ -0,0 +1,130 @@ +assertSame('Title', $type->title); + $this->assertSame('Description', $type->description); + $this->assertSame('Payload', $type->payload); + $this->assertSame('XTR', $type->currency); + $this->assertSame([$price], $type->prices); + $this->assertNull($type->providerToken); + $this->assertNull($type->maxTipAmount); + $this->assertNull($type->suggestedTipAmounts); + $this->assertNull($type->providerData); + $this->assertNull($type->photoUrl); + $this->assertNull($type->photoSize); + $this->assertNull($type->photoWidth); + $this->assertNull($type->photoHeight); + $this->assertNull($type->needName); + $this->assertNull($type->needPhoneNumber); + $this->assertNull($type->needEmail); + $this->assertNull($type->needShippingAddress); + $this->assertNull($type->sendPhoneNumberToProvider); + $this->assertNull($type->sendEmailToProvider); + $this->assertNull($type->isFlexible); + + $this->assertSame( + [ + 'title' => 'Title', + 'description' => 'Description', + 'payload' => 'Payload', + 'currency' => 'XTR', + 'prices' => [$price->toRequestArray()], + ], + $type->toRequestArray(), + ); + } + + public function testFull(): void + { + $price = new LabeledPrice('label', 10); + $type = new InputInvoiceMessageContent( + 'Title', + 'Description', + 'Payload', + 'XTR', + [$price], + 'ProviderToken', + 100, + [10, 20, 30], + 'ProviderData', + 'https://example.com/photo.png', + 205654, + 1024, + 768, + true, + false, + true, + true, + true, + true, + false, + ); + + $this->assertSame('Title', $type->title); + $this->assertSame('Description', $type->description); + $this->assertSame('Payload', $type->payload); + $this->assertSame('XTR', $type->currency); + $this->assertSame([$price], $type->prices); + $this->assertSame('ProviderToken', $type->providerToken); + $this->assertSame(100, $type->maxTipAmount); + $this->assertSame([10, 20, 30], $type->suggestedTipAmounts); + $this->assertSame('ProviderData', $type->providerData); + $this->assertSame('https://example.com/photo.png', $type->photoUrl); + $this->assertSame(205654, $type->photoSize); + $this->assertSame(1024, $type->photoWidth); + $this->assertSame(768, $type->photoHeight); + $this->assertTrue($type->needName); + $this->assertFalse($type->needPhoneNumber); + $this->assertTrue($type->needEmail); + $this->assertTrue($type->needShippingAddress); + $this->assertTrue($type->sendPhoneNumberToProvider); + $this->assertTrue($type->sendEmailToProvider); + $this->assertFalse($type->isFlexible); + + $this->assertSame( + [ + 'title' => 'Title', + 'description' => 'Description', + 'payload' => 'Payload', + 'provider_token' => 'ProviderToken', + 'currency' => 'XTR', + 'prices' => [$price->toRequestArray()], + 'max_tip_amount' => 100, + 'suggested_tip_amounts' => [10, 20, 30], + 'provider_data' => 'ProviderData', + 'photo_url' => 'https://example.com/photo.png', + 'photo_size' => 205654, + 'photo_width' => 1024, + 'photo_height' => 768, + 'need_name' => true, + 'need_phone_number' => false, + 'need_email' => true, + 'need_shipping_address' => true, + 'send_phone_number_to_provider' => true, + 'send_email_to_provider' => true, + 'is_flexible' => false, + ], + $type->toRequestArray(), + ); + } +} diff --git a/tests/Type/Inline/InputLocationMessageContentTest.php b/tests/Type/Inline/InputLocationMessageContentTest.php new file mode 100644 index 0000000..67aea42 --- /dev/null +++ b/tests/Type/Inline/InputLocationMessageContentTest.php @@ -0,0 +1,53 @@ +assertSame(1.1, $type->latitude); + $this->assertSame(2.2, $type->longitude); + $this->assertNull($type->horizontalAccuracy); + $this->assertNull($type->livePeriod); + $this->assertNull($type->heading); + $this->assertNull($type->proximityAlertRadius); + $this->assertSame( + [ + 'latitude' => 1.1, + 'longitude' => 2.2, + ], + $type->toRequestArray(), + ); + } + + public function testFull(): void + { + $type = new InputLocationMessageContent(1.1, 2.2, 3.4, 60, 90, 100); + + $this->assertSame(1.1, $type->latitude); + $this->assertSame(2.2, $type->longitude); + $this->assertSame(3.4, $type->horizontalAccuracy); + $this->assertSame(60, $type->livePeriod); + $this->assertSame(90, $type->heading); + $this->assertSame(100, $type->proximityAlertRadius); + $this->assertSame( + [ + 'latitude' => 1.1, + 'longitude' => 2.2, + 'horizontal_accuracy' => 3.4, + 'live_period' => 60, + 'heading' => 90, + 'proximity_alert_radius' => 100, + ], + $type->toRequestArray(), + ); + } +} diff --git a/tests/Type/Inline/InputTextMessageContentTest.php b/tests/Type/Inline/InputTextMessageContentTest.php new file mode 100644 index 0000000..a0f4a92 --- /dev/null +++ b/tests/Type/Inline/InputTextMessageContentTest.php @@ -0,0 +1,52 @@ +assertSame('Hello', $type->messageText); + $this->assertNull($type->parseMode); + $this->assertNull($type->entities); + $this->assertNull($type->linkPreviewOptions); + $this->assertSame( + [ + 'message_text' => 'Hello', + ], + $type->toRequestArray(), + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $linkPreviewOptions = new LinkPreviewOptions(false); + $type = new InputTextMessageContent('Hello', 'MarkdownV2', [$entity], $linkPreviewOptions); + + $this->assertSame('Hello', $type->messageText); + $this->assertSame('MarkdownV2', $type->parseMode); + $this->assertSame([$entity], $type->entities); + $this->assertSame($linkPreviewOptions, $type->linkPreviewOptions); + $this->assertSame( + [ + 'message_text' => 'Hello', + 'parse_mode' => 'MarkdownV2', + 'entities' => [ + $entity->toRequestArray(), + ], + 'link_preview_options' => $linkPreviewOptions->toRequestArray(), + ], + $type->toRequestArray(), + ); + } +} diff --git a/tests/Type/Inline/InputVenueMessageContentTest.php b/tests/Type/Inline/InputVenueMessageContentTest.php new file mode 100644 index 0000000..fdf6578 --- /dev/null +++ b/tests/Type/Inline/InputVenueMessageContentTest.php @@ -0,0 +1,61 @@ +assertSame(1.1, $type->latitude); + $this->assertSame(2.2, $type->longitude); + $this->assertSame('Title', $type->title); + $this->assertSame('Address', $type->address); + $this->assertNull($type->foursquareId); + $this->assertNull($type->foursquareType); + $this->assertNull($type->googlePlaceId); + $this->assertNull($type->googlePlaceType); + $this->assertSame( + [ + 'latitude' => 1.1, + 'longitude' => 2.2, + 'title' => 'Title', + 'address' => 'Address', + ], + $type->toRequestArray(), + ); + } + + public function testFull(): void + { + $type = new InputVenueMessageContent(1.1, 2.2, 'Title', 'Address', 'fid', 'ftype', 'gid', 'gtype'); + + $this->assertSame(1.1, $type->latitude); + $this->assertSame(2.2, $type->longitude); + $this->assertSame('Title', $type->title); + $this->assertSame('Address', $type->address); + $this->assertSame('fid', $type->foursquareId); + $this->assertSame('ftype', $type->foursquareType); + $this->assertSame('gid', $type->googlePlaceId); + $this->assertSame('gtype', $type->googlePlaceType); + $this->assertSame( + [ + 'latitude' => 1.1, + 'longitude' => 2.2, + 'title' => 'Title', + 'address' => 'Address', + 'foursquare_id' => 'fid', + 'foursquare_type' => 'ftype', + 'google_place_id' => 'gid', + 'google_place_type' => 'gtype', + ], + $type->toRequestArray(), + ); + } +} From 73965ad528caf329cf468a8b5516bc2b3201763d Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 29 Jun 2024 12:37:03 +0300 Subject: [PATCH 4/7] Add `InlineQueryResult*` --- src/Type/Inline/InlineQueryResult.php | 15 ++++ src/Type/Inline/InlineQueryResultArticle.php | 52 +++++++++++ src/Type/Inline/InlineQueryResultAudio.php | 59 +++++++++++++ .../Inline/InlineQueryResultCachedAudio.php | 53 ++++++++++++ .../InlineQueryResultCachedDocument.php | 57 ++++++++++++ .../Inline/InlineQueryResultCachedGif.php | 57 ++++++++++++ .../InlineQueryResultCachedMpeg4Gif.php | 57 ++++++++++++ .../Inline/InlineQueryResultCachedPhoto.php | 59 +++++++++++++ .../Inline/InlineQueryResultCachedSticker.php | 40 +++++++++ .../Inline/InlineQueryResultCachedVideo.php | 59 +++++++++++++ .../Inline/InlineQueryResultCachedVoice.php | 54 ++++++++++++ src/Type/Inline/InlineQueryResultContact.php | 52 +++++++++++ src/Type/Inline/InlineQueryResultDocument.php | 65 ++++++++++++++ src/Type/Inline/InlineQueryResultGame.php | 38 ++++++++ src/Type/Inline/InlineQueryResultGif.php | 67 +++++++++++++++ src/Type/Inline/InlineQueryResultLocation.php | 58 +++++++++++++ src/Type/Inline/InlineQueryResultMpeg4Gif.php | 67 +++++++++++++++ src/Type/Inline/InlineQueryResultPhoto.php | 65 ++++++++++++++ src/Type/Inline/InlineQueryResultVenue.php | 60 +++++++++++++ src/Type/Inline/InlineQueryResultVideo.php | 69 +++++++++++++++ src/Type/Inline/InlineQueryResultVoice.php | 57 ++++++++++++ .../Inline/InlineQueryResultArticleTest.php | 71 +++++++++++++++ .../Inline/InlineQueryResultAudioTest.php | 72 ++++++++++++++++ .../InlineQueryResultCachedAudioTest.php | 64 ++++++++++++++ .../InlineQueryResultCachedDocumentTest.php | 70 +++++++++++++++ .../Inline/InlineQueryResultCachedGifTest.php | 68 +++++++++++++++ .../InlineQueryResultCachedMpeg4GifTest.php | 68 +++++++++++++++ .../InlineQueryResultCachedPhotoTest.php | 70 +++++++++++++++ .../InlineQueryResultCachedStickerTest.php | 56 ++++++++++++ .../InlineQueryResultCachedVideoTest.php | 72 ++++++++++++++++ .../InlineQueryResultCachedVoiceTest.php | 68 +++++++++++++++ .../Inline/InlineQueryResultContactTest.php | 70 +++++++++++++++ .../Inline/InlineQueryResultDocumentTest.php | 80 +++++++++++++++++ .../Type/Inline/InlineQueryResultGameTest.php | 52 +++++++++++ .../Type/Inline/InlineQueryResultGifTest.php | 80 +++++++++++++++++ .../Inline/InlineQueryResultLocationTest.php | 78 +++++++++++++++++ .../Inline/InlineQueryResultMpeg4GifTest.php | 80 +++++++++++++++++ .../Inline/InlineQueryResultPhotoTest.php | 78 +++++++++++++++++ .../Inline/InlineQueryResultVenueTest.php | 82 ++++++++++++++++++ .../Inline/InlineQueryResultVideoTest.php | 86 +++++++++++++++++++ .../Inline/InlineQueryResultVoiceTest.php | 70 +++++++++++++++ 41 files changed, 2595 insertions(+) create mode 100644 src/Type/Inline/InlineQueryResult.php create mode 100644 src/Type/Inline/InlineQueryResultArticle.php create mode 100644 src/Type/Inline/InlineQueryResultAudio.php create mode 100644 src/Type/Inline/InlineQueryResultCachedAudio.php create mode 100644 src/Type/Inline/InlineQueryResultCachedDocument.php create mode 100644 src/Type/Inline/InlineQueryResultCachedGif.php create mode 100644 src/Type/Inline/InlineQueryResultCachedMpeg4Gif.php create mode 100644 src/Type/Inline/InlineQueryResultCachedPhoto.php create mode 100644 src/Type/Inline/InlineQueryResultCachedSticker.php create mode 100644 src/Type/Inline/InlineQueryResultCachedVideo.php create mode 100644 src/Type/Inline/InlineQueryResultCachedVoice.php create mode 100644 src/Type/Inline/InlineQueryResultContact.php create mode 100644 src/Type/Inline/InlineQueryResultDocument.php create mode 100644 src/Type/Inline/InlineQueryResultGame.php create mode 100644 src/Type/Inline/InlineQueryResultGif.php create mode 100644 src/Type/Inline/InlineQueryResultLocation.php create mode 100644 src/Type/Inline/InlineQueryResultMpeg4Gif.php create mode 100644 src/Type/Inline/InlineQueryResultPhoto.php create mode 100644 src/Type/Inline/InlineQueryResultVenue.php create mode 100644 src/Type/Inline/InlineQueryResultVideo.php create mode 100644 src/Type/Inline/InlineQueryResultVoice.php create mode 100644 tests/Type/Inline/InlineQueryResultArticleTest.php create mode 100644 tests/Type/Inline/InlineQueryResultAudioTest.php create mode 100644 tests/Type/Inline/InlineQueryResultCachedAudioTest.php create mode 100644 tests/Type/Inline/InlineQueryResultCachedDocumentTest.php create mode 100644 tests/Type/Inline/InlineQueryResultCachedGifTest.php create mode 100644 tests/Type/Inline/InlineQueryResultCachedMpeg4GifTest.php create mode 100644 tests/Type/Inline/InlineQueryResultCachedPhotoTest.php create mode 100644 tests/Type/Inline/InlineQueryResultCachedStickerTest.php create mode 100644 tests/Type/Inline/InlineQueryResultCachedVideoTest.php create mode 100644 tests/Type/Inline/InlineQueryResultCachedVoiceTest.php create mode 100644 tests/Type/Inline/InlineQueryResultContactTest.php create mode 100644 tests/Type/Inline/InlineQueryResultDocumentTest.php create mode 100644 tests/Type/Inline/InlineQueryResultGameTest.php create mode 100644 tests/Type/Inline/InlineQueryResultGifTest.php create mode 100644 tests/Type/Inline/InlineQueryResultLocationTest.php create mode 100644 tests/Type/Inline/InlineQueryResultMpeg4GifTest.php create mode 100644 tests/Type/Inline/InlineQueryResultPhotoTest.php create mode 100644 tests/Type/Inline/InlineQueryResultVenueTest.php create mode 100644 tests/Type/Inline/InlineQueryResultVideoTest.php create mode 100644 tests/Type/Inline/InlineQueryResultVoiceTest.php diff --git a/src/Type/Inline/InlineQueryResult.php b/src/Type/Inline/InlineQueryResult.php new file mode 100644 index 0000000..b4a3f91 --- /dev/null +++ b/src/Type/Inline/InlineQueryResult.php @@ -0,0 +1,15 @@ + $this->getType(), + 'id' => $this->id, + 'title' => $this->title, + 'input_message_content' => $this->inputMessageContent->toRequestArray(), + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'url' => $this->url, + 'hide_url' => $this->hideUrl, + 'description' => $this->description, + 'thumbnail_url' => $this->thumbnailUrl, + 'thumbnail_width' => $this->thumbnailWidth, + 'thumbnail_height' => $this->thumbnailHeight, + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultAudio.php b/src/Type/Inline/InlineQueryResultAudio.php new file mode 100644 index 0000000..6ab74de --- /dev/null +++ b/src/Type/Inline/InlineQueryResultAudio.php @@ -0,0 +1,59 @@ + $this->getType(), + 'id' => $this->id, + 'audio_url' => $this->audioUrl, + 'title' => $this->title, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'performer' => $this->performer, + 'audio_duration' => $this->audioDuration, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultCachedAudio.php b/src/Type/Inline/InlineQueryResultCachedAudio.php new file mode 100644 index 0000000..163b92e --- /dev/null +++ b/src/Type/Inline/InlineQueryResultCachedAudio.php @@ -0,0 +1,53 @@ + $this->getType(), + 'id' => $this->id, + 'audio_file_id' => $this->audioFileId, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultCachedDocument.php b/src/Type/Inline/InlineQueryResultCachedDocument.php new file mode 100644 index 0000000..453ed1c --- /dev/null +++ b/src/Type/Inline/InlineQueryResultCachedDocument.php @@ -0,0 +1,57 @@ + $this->getType(), + 'id' => $this->id, + 'title' => $this->title, + 'document_file_id' => $this->documentFileId, + 'description' => $this->description, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultCachedGif.php b/src/Type/Inline/InlineQueryResultCachedGif.php new file mode 100644 index 0000000..a23e643 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultCachedGif.php @@ -0,0 +1,57 @@ + $this->getType(), + 'id' => $this->id, + 'gif_file_id' => $this->gifFileId, + 'title' => $this->title, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'show_caption_above_media' => $this->showCaptionAboveMedia, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultCachedMpeg4Gif.php b/src/Type/Inline/InlineQueryResultCachedMpeg4Gif.php new file mode 100644 index 0000000..3232d40 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultCachedMpeg4Gif.php @@ -0,0 +1,57 @@ + $this->getType(), + 'id' => $this->id, + 'mpeg4_file_id' => $this->mpeg4FileId, + 'title' => $this->title, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'show_caption_above_media' => $this->showCaptionAboveMedia, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultCachedPhoto.php b/src/Type/Inline/InlineQueryResultCachedPhoto.php new file mode 100644 index 0000000..887de56 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultCachedPhoto.php @@ -0,0 +1,59 @@ + $this->getType(), + 'id' => $this->id, + 'photo_file_id' => $this->photoFileId, + 'title' => $this->title, + 'description' => $this->description, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'show_caption_above_media' => $this->showCaptionAboveMedia, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultCachedSticker.php b/src/Type/Inline/InlineQueryResultCachedSticker.php new file mode 100644 index 0000000..9a584c5 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultCachedSticker.php @@ -0,0 +1,40 @@ + $this->getType(), + 'id' => $this->id, + 'sticker_file_id' => $this->stickerFileId, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultCachedVideo.php b/src/Type/Inline/InlineQueryResultCachedVideo.php new file mode 100644 index 0000000..7153916 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultCachedVideo.php @@ -0,0 +1,59 @@ + $this->getType(), + 'id' => $this->id, + 'video_file_id' => $this->videoFileId, + 'title' => $this->title, + 'description' => $this->description, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'show_caption_above_media' => $this->showCaptionAboveMedia, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultCachedVoice.php b/src/Type/Inline/InlineQueryResultCachedVoice.php new file mode 100644 index 0000000..a990066 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultCachedVoice.php @@ -0,0 +1,54 @@ + $this->getType(), + 'id' => $this->id, + 'voice_file_id' => $this->voiceFileId, + 'title' => $this->title, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultContact.php b/src/Type/Inline/InlineQueryResultContact.php new file mode 100644 index 0000000..309bd45 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultContact.php @@ -0,0 +1,52 @@ + $this->getType(), + 'id' => $this->id, + 'phone_number' => $this->phoneNumber, + 'first_name' => $this->firstName, + 'last_name' => $this->lastName, + 'vcard' => $this->vcard, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + 'thumbnail_url' => $this->thumbnailUrl, + 'thumbnail_width' => $this->thumbnailWidth, + 'thumbnail_height' => $this->thumbnailHeight, + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultDocument.php b/src/Type/Inline/InlineQueryResultDocument.php new file mode 100644 index 0000000..3fb5dea --- /dev/null +++ b/src/Type/Inline/InlineQueryResultDocument.php @@ -0,0 +1,65 @@ + $this->getType(), + 'id' => $this->id, + 'title' => $this->title, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'document_url' => $this->documentUrl, + 'mime_type' => $this->mimeType, + 'description' => $this->description, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + 'thumbnail_url' => $this->thumbnailUrl, + 'thumbnail_width' => $this->thumbnailWidth, + 'thumbnail_height' => $this->thumbnailHeight, + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultGame.php b/src/Type/Inline/InlineQueryResultGame.php new file mode 100644 index 0000000..83c4527 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultGame.php @@ -0,0 +1,38 @@ + $this->getType(), + 'id' => $this->id, + 'game_short_name' => $this->gameShortName, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultGif.php b/src/Type/Inline/InlineQueryResultGif.php new file mode 100644 index 0000000..bd4f560 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultGif.php @@ -0,0 +1,67 @@ + $this->getType(), + 'id' => $this->id, + 'gif_url' => $this->gifUrl, + 'gif_width' => $this->gifWidth, + 'gif_height' => $this->gifHeight, + 'gif_duration' => $this->gifDuration, + 'thumbnail_url' => $this->thumbnailUrl, + 'thumbnail_mime_type' => $this->thumbnailMimeType, + 'title' => $this->title, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'show_caption_above_media' => $this->showCaptionAboveMedia, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultLocation.php b/src/Type/Inline/InlineQueryResultLocation.php new file mode 100644 index 0000000..814f91b --- /dev/null +++ b/src/Type/Inline/InlineQueryResultLocation.php @@ -0,0 +1,58 @@ + $this->getType(), + 'id' => $this->id, + 'latitude' => $this->latitude, + 'longitude' => $this->longitude, + 'title' => $this->title, + 'horizontal_accuracy' => $this->horizontalAccuracy, + 'live_period' => $this->livePeriod, + 'heading' => $this->heading, + 'proximity_alert_radius' => $this->proximityAlertRadius, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + 'thumbnail_url' => $this->thumbnailUrl, + 'thumbnail_width' => $this->thumbnailWidth, + 'thumbnail_height' => $this->thumbnailHeight, + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultMpeg4Gif.php b/src/Type/Inline/InlineQueryResultMpeg4Gif.php new file mode 100644 index 0000000..2690802 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultMpeg4Gif.php @@ -0,0 +1,67 @@ + $this->getType(), + 'id' => $this->id, + 'mpeg4_url' => $this->mpeg4Url, + 'mpeg4_width' => $this->mpeg4Width, + 'mpeg4_height' => $this->mpeg4Height, + 'mpeg4_duration' => $this->mpeg4Duration, + 'thumbnail_url' => $this->thumbnailUrl, + 'thumbnail_mime_type' => $this->thumbnailMimeType, + 'title' => $this->title, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'show_caption_above_media' => $this->showCaptionAboveMedia, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultPhoto.php b/src/Type/Inline/InlineQueryResultPhoto.php new file mode 100644 index 0000000..631ac8e --- /dev/null +++ b/src/Type/Inline/InlineQueryResultPhoto.php @@ -0,0 +1,65 @@ + $this->getType(), + 'id' => $this->id, + 'photo_url' => $this->photoUrl, + 'thumbnail_url' => $this->thumbnailUrl, + 'photo_width' => $this->photoWidth, + 'photo_height' => $this->photoHeight, + 'title' => $this->title, + 'description' => $this->description, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'show_caption_above_media' => $this->showCaptionAboveMedia, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultVenue.php b/src/Type/Inline/InlineQueryResultVenue.php new file mode 100644 index 0000000..6993cd6 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultVenue.php @@ -0,0 +1,60 @@ + $this->getType(), + 'id' => $this->id, + 'latitude' => $this->latitude, + 'longitude' => $this->longitude, + 'title' => $this->title, + 'address' => $this->address, + 'foursquare_id' => $this->foursquareId, + 'foursquare_type' => $this->foursquareType, + 'google_place_id' => $this->googlePlaceId, + 'google_place_type' => $this->googlePlaceType, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + 'thumbnail_url' => $this->thumbnailUrl, + 'thumbnail_width' => $this->thumbnailWidth, + 'thumbnail_height' => $this->thumbnailHeight, + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultVideo.php b/src/Type/Inline/InlineQueryResultVideo.php new file mode 100644 index 0000000..5baa727 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultVideo.php @@ -0,0 +1,69 @@ + $this->getType(), + 'id' => $this->id, + 'video_url' => $this->videoUrl, + 'mime_type' => $this->mimeType, + 'thumbnail_url' => $this->thumbnailUrl, + 'title' => $this->title, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'show_caption_above_media' => $this->showCaptionAboveMedia, + 'video_width' => $this->videoWidth, + 'video_height' => $this->videoHeight, + 'video_duration' => $this->videoDuration, + 'description' => $this->description, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Inline/InlineQueryResultVoice.php b/src/Type/Inline/InlineQueryResultVoice.php new file mode 100644 index 0000000..7c230e7 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultVoice.php @@ -0,0 +1,57 @@ + $this->getType(), + 'id' => $this->id, + 'voice_url' => $this->voiceUrl, + 'title' => $this->title, + 'caption' => $this->caption, + 'parse_mode' => $this->parseMode, + 'caption_entities' => $this->captionEntities === null ? null : array_map( + static fn(MessageEntity $entity) => $entity->toRequestArray(), + $this->captionEntities, + ), + 'voice_duration' => $this->voiceDuration, + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + 'input_message_content' => $this->inputMessageContent?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultArticleTest.php b/tests/Type/Inline/InlineQueryResultArticleTest.php new file mode 100644 index 0000000..01febc5 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultArticleTest.php @@ -0,0 +1,71 @@ +assertSame('article', $type->getType()); + $this->assertSame( + [ + 'type' => 'article', + 'id' => 'id', + 'title' => 'title', + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultArticle( + 'id', + 'title', + $inputMessageContent, + $replyMarkup, + 'https://example.com', + true, + 'any desc', + 'https://example.com/thumb.png', + 100, + 200, + ); + + $this->assertSame('article', $type->getType()); + $this->assertSame( + [ + 'type' => 'article', + 'id' => 'id', + 'title' => 'title', + 'input_message_content' => $inputMessageContent->toRequestArray(), + 'reply_markup' => $replyMarkup->toRequestArray(), + 'url' => 'https://example.com', + 'hide_url' => true, + 'description' => 'any desc', + 'thumbnail_url' => 'https://example.com/thumb.png', + 'thumbnail_width' => 100, + 'thumbnail_height' => 200, + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultAudioTest.php b/tests/Type/Inline/InlineQueryResultAudioTest.php new file mode 100644 index 0000000..6a308c5 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultAudioTest.php @@ -0,0 +1,72 @@ +assertSame('audio', $type->getType()); + $this->assertSame( + [ + 'type' => 'audio', + 'id' => 'id1', + 'audio_url' => 'https://example.com/test.mp3', + 'title' => 'The title', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultAudio( + 'id1', + 'https://example.com/test.mp3', + 'The title', + 'The caption', + 'HTML', + [$entity], + 'The performer', + 15, + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('audio', $type->getType()); + $this->assertSame( + [ + 'type' => 'audio', + 'id' => 'id1', + 'audio_url' => 'https://example.com/test.mp3', + 'title' => 'The title', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'performer' => 'The performer', + 'audio_duration' => 15, + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultCachedAudioTest.php b/tests/Type/Inline/InlineQueryResultCachedAudioTest.php new file mode 100644 index 0000000..8a8ae2a --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultCachedAudioTest.php @@ -0,0 +1,64 @@ +assertSame('audio', $type->getType()); + $this->assertSame( + [ + 'type' => 'audio', + 'id' => 'id1', + 'audio_file_id' => 'audio_id1', + ], + $type->toRequestArray() + ); + } + + public function testFull():void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultCachedAudio( + 'id1', + 'audio_id1', + 'The caption', + 'HTML', + [$entity], + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('audio', $type->getType()); + $this->assertSame( + [ + 'type' => 'audio', + 'id' => 'id1', + 'audio_file_id' => 'audio_id1', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultCachedDocumentTest.php b/tests/Type/Inline/InlineQueryResultCachedDocumentTest.php new file mode 100644 index 0000000..b8231ec --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultCachedDocumentTest.php @@ -0,0 +1,70 @@ +assertSame('document', $type->getType()); + $this->assertSame( + [ + 'type' => 'document', + 'id' => 'id1', + 'title' => 'The Title', + 'document_file_id' => 'document_id1', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultCachedDocument( + 'id1', + 'The Title', + 'document_id1', + 'The description', + 'The caption', + 'HTML', + [$entity], + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('document', $type->getType()); + $this->assertSame( + [ + 'type' => 'document', + 'id' => 'id1', + 'title' => 'The Title', + 'document_file_id' => 'document_id1', + 'description' => 'The description', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultCachedGifTest.php b/tests/Type/Inline/InlineQueryResultCachedGifTest.php new file mode 100644 index 0000000..c23c5b1 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultCachedGifTest.php @@ -0,0 +1,68 @@ +assertSame('gif', $type->getType()); + $this->assertSame( + [ + 'type' => 'gif', + 'id' => 'id1', + 'gif_file_id' => 'gif_id1', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultCachedGif( + 'id1', + 'gif_id1', + 'The title', + 'The caption', + 'HTML', + [$entity], + true, + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('gif', $type->getType()); + $this->assertSame( + [ + 'type' => 'gif', + 'id' => 'id1', + 'gif_file_id' => 'gif_id1', + 'title' => 'The title', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'show_caption_above_media' => true, + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultCachedMpeg4GifTest.php b/tests/Type/Inline/InlineQueryResultCachedMpeg4GifTest.php new file mode 100644 index 0000000..07bba10 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultCachedMpeg4GifTest.php @@ -0,0 +1,68 @@ +assertSame('mpeg4_gif', $type->getType()); + $this->assertSame( + [ + 'type' => 'mpeg4_gif', + 'id' => 'id1', + 'mpeg4_file_id' => 'mpeg4_gif_id1', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultCachedMpeg4Gif( + 'id1', + 'mpeg4_gif_id1', + 'The title', + 'The caption', + 'HTML', + [$entity], + true, + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('mpeg4_gif', $type->getType()); + $this->assertSame( + [ + 'type' => 'mpeg4_gif', + 'id' => 'id1', + 'mpeg4_file_id' => 'mpeg4_gif_id1', + 'title' => 'The title', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'show_caption_above_media' => true, + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultCachedPhotoTest.php b/tests/Type/Inline/InlineQueryResultCachedPhotoTest.php new file mode 100644 index 0000000..510d81c --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultCachedPhotoTest.php @@ -0,0 +1,70 @@ +assertSame('photo', $type->getType()); + $this->assertSame( + [ + 'type' => 'photo', + 'id' => 'id1', + 'photo_file_id' => 'photo_id1', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultCachedPhoto( + 'id1', + 'photo_id1', + 'The title', + 'The description', + 'The caption', + 'HTML', + [$entity], + true, + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('photo', $type->getType()); + $this->assertSame( + [ + 'type' => 'photo', + 'id' => 'id1', + 'photo_file_id' => 'photo_id1', + 'title' => 'The title', + 'description' => 'The description', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'show_caption_above_media' => true, + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultCachedStickerTest.php b/tests/Type/Inline/InlineQueryResultCachedStickerTest.php new file mode 100644 index 0000000..ce9d0ae --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultCachedStickerTest.php @@ -0,0 +1,56 @@ +assertSame('sticker', $type->getType()); + $this->assertSame( + [ + 'type' => 'sticker', + 'id' => 'id1', + 'sticker_file_id' => 'sticker_id1', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultCachedSticker( + 'id1', + 'sticker_id1', + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('sticker', $type->getType()); + $this->assertSame( + [ + 'type' => 'sticker', + 'id' => 'id1', + 'sticker_file_id' => 'sticker_id1', + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultCachedVideoTest.php b/tests/Type/Inline/InlineQueryResultCachedVideoTest.php new file mode 100644 index 0000000..457fe82 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultCachedVideoTest.php @@ -0,0 +1,72 @@ +assertSame('video', $type->getType()); + $this->assertSame( + [ + 'type' => 'video', + 'id' => 'id1', + 'video_file_id' => 'video_id1', + 'title' => 'The title', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultCachedVideo( + 'id1', + 'video_id1', + 'The title', + 'The description', + 'The caption', + 'HTML', + [$entity], + true, + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('video', $type->getType()); + $this->assertSame( + [ + 'type' => 'video', + 'id' => 'id1', + 'video_file_id' => 'video_id1', + 'title' => 'The title', + 'description' => 'The description', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'show_caption_above_media' => true, + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultCachedVoiceTest.php b/tests/Type/Inline/InlineQueryResultCachedVoiceTest.php new file mode 100644 index 0000000..6979f5e --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultCachedVoiceTest.php @@ -0,0 +1,68 @@ +assertSame('voice', $type->getType()); + $this->assertSame( + [ + 'type' => 'voice', + 'id' => 'id1', + 'voice_file_id' => 'voice_id1', + 'title' => 'The title', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultCachedVoice( + 'id1', + 'voice_id1', + 'The title', + 'The caption', + 'HTML', + [$entity], + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('voice', $type->getType()); + $this->assertSame( + [ + 'type' => 'voice', + 'id' => 'id1', + 'voice_file_id' => 'voice_id1', + 'title' => 'The title', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultContactTest.php b/tests/Type/Inline/InlineQueryResultContactTest.php new file mode 100644 index 0000000..09fe8f7 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultContactTest.php @@ -0,0 +1,70 @@ +assertSame('contact', $type->getType()); + $this->assertSame( + [ + 'type' => 'contact', + 'id' => 'id1', + 'phone_number' => '+79001234567', + 'first_name' => 'Sergei', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultContact( + 'id1', + '+79001234567', + 'Sergei', + 'Predvoditelev', + 'myvcard', + $replyMarkup, + $inputMessageContent, + 'https://example.com/test.jpg', + 120, + 200, + ); + + $this->assertSame('contact', $type->getType()); + $this->assertSame( + [ + 'type' => 'contact', + 'id' => 'id1', + 'phone_number' => '+79001234567', + 'first_name' => 'Sergei', + 'last_name' => 'Predvoditelev', + 'vcard' => 'myvcard', + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + 'thumbnail_url' => 'https://example.com/test.jpg', + 'thumbnail_width' => 120, + 'thumbnail_height' => 200, + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultDocumentTest.php b/tests/Type/Inline/InlineQueryResultDocumentTest.php new file mode 100644 index 0000000..9be3703 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultDocumentTest.php @@ -0,0 +1,80 @@ +assertSame('document', $type->getType()); + $this->assertSame( + [ + 'type' => 'document', + 'id' => 'id1', + 'title' => 'The title', + 'document_url' => 'https://example.com/test.pdf', + 'mime_type' => 'application/pdf', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultDocument( + 'id1', + 'The title', + 'https://example.com/test.pdf', + 'application/pdf', + 'The caption', + 'HTML', + [$entity], + 'The description', + $replyMarkup, + $inputMessageContent, + 'https://example.com/test.jpg', + 120, + 150, + ); + + $this->assertSame('document', $type->getType()); + $this->assertSame( + [ + 'type' => 'document', + 'id' => 'id1', + 'title' => 'The title', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'document_url' => 'https://example.com/test.pdf', + 'mime_type' => 'application/pdf', + 'description' => 'The description', + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + 'thumbnail_url' => 'https://example.com/test.jpg', + 'thumbnail_width' => 120, + 'thumbnail_height' => 150, + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultGameTest.php b/tests/Type/Inline/InlineQueryResultGameTest.php new file mode 100644 index 0000000..ffca760 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultGameTest.php @@ -0,0 +1,52 @@ +assertSame('game', $type->getType()); + $this->assertSame( + [ + 'type' => 'game', + 'id' => 'id1', + 'game_short_name' => 'the game', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultGame( + 'id1', + 'the game', + $replyMarkup + ); + + $this->assertSame('game', $type->getType()); + $this->assertSame( + [ + 'type' => 'game', + 'id' => 'id1', + 'game_short_name' => 'the game', + 'reply_markup' => $replyMarkup->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultGifTest.php b/tests/Type/Inline/InlineQueryResultGifTest.php new file mode 100644 index 0000000..409202c --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultGifTest.php @@ -0,0 +1,80 @@ +assertSame('gif', $type->getType()); + $this->assertSame( + [ + 'type' => 'gif', + 'id' => 'id1', + 'gif_url' => 'https://example.com/test.gif', + 'thumbnail_url' => 'https://example.com/th.jpg', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultGif( + 'id1', + 'https://example.com/test.gif', + 'https://example.com/th.jpg', + 100, + 200, + 15, + 'image/jpeg', + 'The title', + 'The caption', + 'HTML', + [$entity], + true, + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('gif', $type->getType()); + $this->assertSame( + [ + 'type' => 'gif', + 'id' => 'id1', + 'gif_url' => 'https://example.com/test.gif', + 'gif_width' => 100, + 'gif_height' => 200, + 'gif_duration' => 15, + 'thumbnail_url' => 'https://example.com/th.jpg', + 'thumbnail_mime_type' => 'image/jpeg', + 'title' => 'The title', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'show_caption_above_media' => true, + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultLocationTest.php b/tests/Type/Inline/InlineQueryResultLocationTest.php new file mode 100644 index 0000000..77bb09a --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultLocationTest.php @@ -0,0 +1,78 @@ +assertSame('location', $type->getType()); + $this->assertSame( + [ + 'type' => 'location', + 'id' => 'id1', + 'latitude' => 59.9386292, + 'longitude' => 30.3141308, + 'title' => 'The title', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultLocation( + 'id1', + 59.9386292, + 30.3141308, + 'The title', + 15.23, + 100, + 200, + 104, + $replyMarkup, + $inputMessageContent, + 'https://example.com/test.jpg', + 532, + 234, + ); + + $this->assertSame('location', $type->getType()); + $this->assertSame( + [ + 'type' => 'location', + 'id' => 'id1', + 'latitude' => 59.9386292, + 'longitude' => 30.3141308, + 'title' => 'The title', + 'horizontal_accuracy' => 15.23, + 'live_period' => 100, + 'heading' => 200, + 'proximity_alert_radius' => 104, + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + 'thumbnail_url' => 'https://example.com/test.jpg', + 'thumbnail_width' => 532, + 'thumbnail_height' => 234, + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultMpeg4GifTest.php b/tests/Type/Inline/InlineQueryResultMpeg4GifTest.php new file mode 100644 index 0000000..74661b5 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultMpeg4GifTest.php @@ -0,0 +1,80 @@ +assertSame('mpeg4_gif', $type->getType()); + $this->assertSame( + [ + 'type' => 'mpeg4_gif', + 'id' => 'id1', + 'mpeg4_url' => 'https://example.com/test.mp4', + 'thumbnail_url' => 'https://example.com/th.jpg', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultMpeg4Gif( + 'id1', + 'https://example.com/test.mp4', + 'https://example.com/th.jpg', + 100, + 200, + 15, + 'image/jpeg', + 'The title', + 'The caption', + 'HTML', + [$entity], + true, + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('mpeg4_gif', $type->getType()); + $this->assertSame( + [ + 'type' => 'mpeg4_gif', + 'id' => 'id1', + 'mpeg4_url' => 'https://example.com/test.mp4', + 'mpeg4_width' => 100, + 'mpeg4_height' => 200, + 'mpeg4_duration' => 15, + 'thumbnail_url' => 'https://example.com/th.jpg', + 'thumbnail_mime_type' => 'image/jpeg', + 'title' => 'The title', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'show_caption_above_media' => true, + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultPhotoTest.php b/tests/Type/Inline/InlineQueryResultPhotoTest.php new file mode 100644 index 0000000..7f01bd8 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultPhotoTest.php @@ -0,0 +1,78 @@ +assertSame('photo', $type->getType()); + $this->assertSame( + [ + 'type' => 'photo', + 'id' => 'id', + 'photo_url' => 'https://example.com/test.jpg', + 'thumbnail_url' => 'https://example.com/th.jpg', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultPhoto( + 'id1', + 'https://example.com/test.jpg', + 'https://example.com/th.jpg', + 100, + 200, + 'The title', + 'Any desc', + 'The caption', + 'HTML', + [$entity], + true, + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('photo', $type->getType()); + $this->assertSame( + [ + 'type' => 'photo', + 'id' => 'id1', + 'photo_url' => 'https://example.com/test.jpg', + 'thumbnail_url' => 'https://example.com/th.jpg', + 'photo_width' => 100, + 'photo_height' => 200, + 'title' => 'The title', + 'description' => 'Any desc', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'show_caption_above_media' => true, + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultVenueTest.php b/tests/Type/Inline/InlineQueryResultVenueTest.php new file mode 100644 index 0000000..96ddfb5 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultVenueTest.php @@ -0,0 +1,82 @@ +assertSame('venue', $type->getType()); + $this->assertSame( + [ + 'type' => 'venue', + 'id' => 'id1', + 'latitude' => 59.9386292, + 'longitude' => 30.3141308, + 'title' => 'The title', + 'address' => 'The address', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultVenue( + 'id1', + 59.9386292, + 30.3141308, + 'The title', + 'The address', + 'The foursquare_id', + 'The foursquare_type', + 'The google_place_id', + 'The google_place_type', + $replyMarkup, + $inputMessageContent, + 'https://example.com/test.jpg', + 120, + 150, + ); + + $this->assertSame('venue', $type->getType()); + $this->assertSame( + [ + 'type' => 'venue', + 'id' => 'id1', + 'latitude' => 59.9386292, + 'longitude' => 30.3141308, + 'title' => 'The title', + 'address' => 'The address', + 'foursquare_id' => 'The foursquare_id', + 'foursquare_type' => 'The foursquare_type', + 'google_place_id' => 'The google_place_id', + 'google_place_type' => 'The google_place_type', + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + 'thumbnail_url' => 'https://example.com/test.jpg', + 'thumbnail_width' => 120, + 'thumbnail_height' => 150, + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultVideoTest.php b/tests/Type/Inline/InlineQueryResultVideoTest.php new file mode 100644 index 0000000..ec08f48 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultVideoTest.php @@ -0,0 +1,86 @@ +assertSame('video', $type->getType()); + $this->assertSame( + [ + 'type' => 'video', + 'id' => 'id1', + 'video_url' => 'https://example.com/test.mp4', + 'mime_type' => 'video/mp4', + 'thumbnail_url' => 'https://example.com/th.jpg', + 'title' => 'The title', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultVideo( + 'id1', + 'https://example.com/test.mp4', + 'video/mp4', + 'https://example.com/th.jpg', + 'The title', + 'The caption', + 'HTML', + [$entity], + true, + 100, + 200, + 15, + 'The description', + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('video', $type->getType()); + $this->assertSame( + [ + 'type' => 'video', + 'id' => 'id1', + 'video_url' => 'https://example.com/test.mp4', + 'mime_type' => 'video/mp4', + 'thumbnail_url' => 'https://example.com/th.jpg', + 'title' => 'The title', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'show_caption_above_media' => true, + 'video_width' => 100, + 'video_height' => 200, + 'video_duration' => 15, + 'description' => 'The description', + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultVoiceTest.php b/tests/Type/Inline/InlineQueryResultVoiceTest.php new file mode 100644 index 0000000..d083b33 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultVoiceTest.php @@ -0,0 +1,70 @@ +assertSame('voice', $type->getType()); + $this->assertSame( + [ + 'type' => 'voice', + 'id' => 'id1', + 'voice_url' => 'https://example.com/test.ogg', + 'title' => 'The title', + ], + $type->toRequestArray() + ); + } + + public function testFull(): void + { + $entity = new MessageEntity('bold', 0, 4); + $inputMessageContent = new InputContactMessageContent('+79001234567', 'Sergei'); + $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('test')]]); + $type = new InlineQueryResultVoice( + 'id1', + 'https://example.com/test.ogg', + 'The title', + 'The caption', + 'HTML', + [$entity], + 15, + $replyMarkup, + $inputMessageContent, + ); + + $this->assertSame('voice', $type->getType()); + $this->assertSame( + [ + 'type' => 'voice', + 'id' => 'id1', + 'voice_url' => 'https://example.com/test.ogg', + 'title' => 'The title', + 'caption' => 'The caption', + 'parse_mode' => 'HTML', + 'caption_entities' => [$entity->toRequestArray()], + 'voice_duration' => 15, + 'reply_markup' => $replyMarkup->toRequestArray(), + 'input_message_content' => $inputMessageContent->toRequestArray(), + ], + $type->toRequestArray() + ); + } +} From 79396b05dddf17e5375236812f9451133386c4e7 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 29 Jun 2024 12:40:52 +0300 Subject: [PATCH 5/7] Add `InlineQueryResultsButton` --- src/Type/Inline/InlineQueryResultsButton.php | 32 +++++++++++++++ .../Inline/InlineQueryResultsButtonTest.php | 39 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/Type/Inline/InlineQueryResultsButton.php create mode 100644 tests/Type/Inline/InlineQueryResultsButtonTest.php diff --git a/src/Type/Inline/InlineQueryResultsButton.php b/src/Type/Inline/InlineQueryResultsButton.php new file mode 100644 index 0000000..fbedb65 --- /dev/null +++ b/src/Type/Inline/InlineQueryResultsButton.php @@ -0,0 +1,32 @@ + $this->text, + 'web_app' => $this->webApp?->toRequestArray(), + 'start_parameter' => $this->startParameter, + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/tests/Type/Inline/InlineQueryResultsButtonTest.php b/tests/Type/Inline/InlineQueryResultsButtonTest.php new file mode 100644 index 0000000..6a4d1c4 --- /dev/null +++ b/tests/Type/Inline/InlineQueryResultsButtonTest.php @@ -0,0 +1,39 @@ +assertSame( + [ + 'text' => 'test', + ], + $type->toRequestArray(), + ); + } + + public function testFull(): void + { + $webApp = new WebAppInfo('https://example.com'); + $type = new InlineQueryResultsButton('test', $webApp, 'start'); + + $this->assertSame( + [ + 'text' => 'test', + 'web_app' => $webApp->toRequestArray(), + 'start_parameter' => 'start', + ], + $type->toRequestArray(), + ); + } +} From 9369e3bd104b36993baaa95f75460faf49ea1fc8 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 29 Jun 2024 12:48:41 +0300 Subject: [PATCH 6/7] Add `answerInlineQuery` --- src/Method/Inline/AnswerInlineQuery.php | 64 +++++++++++++++++++ src/TelegramBotApi.php | 23 +++++++ tests/Method/Inline/AnswerInlineQueryTest.php | 61 ++++++++++++++++++ tests/TelegramBotApiTest.php | 12 ++++ 4 files changed, 160 insertions(+) create mode 100644 src/Method/Inline/AnswerInlineQuery.php create mode 100644 tests/Method/Inline/AnswerInlineQueryTest.php diff --git a/src/Method/Inline/AnswerInlineQuery.php b/src/Method/Inline/AnswerInlineQuery.php new file mode 100644 index 0000000..1c40691 --- /dev/null +++ b/src/Method/Inline/AnswerInlineQuery.php @@ -0,0 +1,64 @@ + $this->inlineQueryId, + 'results' => array_map( + static fn(InlineQueryResult $result) => $result->toRequestArray(), + $this->results, + ), + 'cache_time' => $this->cacheTime, + 'is_personal' => $this->isPersonal, + 'next_offset' => $this->nextOffset, + 'button' => $this->button?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } + + public function prepareResult(mixed $result): true + { + ValueHelper::assertTrueResult($result); + return $result; + } +} diff --git a/src/TelegramBotApi.php b/src/TelegramBotApi.php index 63c49fc..2325a2d 100644 --- a/src/TelegramBotApi.php +++ b/src/TelegramBotApi.php @@ -47,6 +47,7 @@ use Vjik\TelegramBot\Api\Method\GetUserChatBoosts; use Vjik\TelegramBot\Api\Method\GetUserProfilePhotos; use Vjik\TelegramBot\Api\Method\HideGeneralForumTopic; +use Vjik\TelegramBot\Api\Method\Inline\AnswerInlineQuery; use Vjik\TelegramBot\Api\Method\LeaveChat; use Vjik\TelegramBot\Api\Method\LogOut; use Vjik\TelegramBot\Api\Method\Payment\GetStarTransactions; @@ -133,6 +134,8 @@ use Vjik\TelegramBot\Api\Type\File; use Vjik\TelegramBot\Api\Type\ForceReply; use Vjik\TelegramBot\Api\Type\ForumTopic; +use Vjik\TelegramBot\Api\Type\Inline\InlineQueryResult; +use Vjik\TelegramBot\Api\Type\Inline\InlineQueryResultsButton; use Vjik\TelegramBot\Api\Type\InlineKeyboardMarkup; use Vjik\TelegramBot\Api\Type\InputFile; use Vjik\TelegramBot\Api\Type\InputMedia; @@ -236,6 +239,26 @@ public function answerCallbackQuery( ); } + /** + * @see https://core.telegram.org/bots/api#answerinlinequery + * + * @param InlineQueryResult[] $results + * + * @psalm-suppress MixedInferredReturnType,MixedReturnStatement + */ + public function answerInlineQuery( + string $inlineQueryId, + array $results, + ?int $cacheTime = null, + ?bool $isPersonal = null, + ?string $nextOffset = null, + ?InlineQueryResultsButton $button = null, + ): FailResult|true { + return $this->send( + new AnswerInlineQuery($inlineQueryId, $results, $cacheTime, $isPersonal, $nextOffset, $button) + ); + } + /** * @see https://core.telegram.org/bots/api#approvechatjoinrequest * diff --git a/tests/Method/Inline/AnswerInlineQueryTest.php b/tests/Method/Inline/AnswerInlineQueryTest.php new file mode 100644 index 0000000..18f601d --- /dev/null +++ b/tests/Method/Inline/AnswerInlineQueryTest.php @@ -0,0 +1,61 @@ +assertSame(HttpMethod::POST, $method->getHttpMethod()); + $this->assertSame('answerInlineQuery', $method->getApiMethod()); + $this->assertSame( + [ + 'inline_query_id' => 'id1', + 'results' => [], + ], + $method->getData() + ); + } + + public function testFull(): void + { + $result = new InlineQueryResultContact('id1', '+79001234567', 'Sergei'); + $button = new InlineQueryResultsButton('test'); + $method = new AnswerInlineQuery('id2', [$result], 500, true, 'n2', $button); + + $this->assertSame(HttpMethod::POST, $method->getHttpMethod()); + $this->assertSame('answerInlineQuery', $method->getApiMethod()); + $this->assertSame( + [ + 'inline_query_id' => 'id2', + 'results' => [ + $result->toRequestArray(), + ], + 'cache_time' => 500, + 'is_personal' => true, + 'next_offset' => 'n2', + 'button' => $button->toRequestArray(), + ], + $method->getData(), + ); + } + + public function testPrepareResult(): void + { + $method = new AnswerInlineQuery('id', []); + + $preparedResult = $method->prepareResult(true); + + $this->assertTrue($preparedResult); + } +} diff --git a/tests/TelegramBotApiTest.php b/tests/TelegramBotApiTest.php index 9ad7690..059467b 100644 --- a/tests/TelegramBotApiTest.php +++ b/tests/TelegramBotApiTest.php @@ -137,6 +137,18 @@ public function testAnswerCallbackQuery(): void $this->assertTrue($result); } + public function testAnswerInlineQuery(): void + { + $api = $this->createApi([ + 'ok' => true, + 'result' => true, + ]); + + $result = $api->answerInlineQuery('id', []); + + $this->assertTrue($result); + } + public function testApproveChatJoinRequest(): void { $api = $this->createApi([ From a3a55a7fe9303c84a47ef86dc32af04b1e58b65e Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 29 Jun 2024 12:51:02 +0300 Subject: [PATCH 7/7] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e900f13..4198920 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,8 @@ - New #76: Add `editMessageReplyMarkup` method. - New #77: Add `stopPoll` method. - New #78: Add `deleteMessage` and `deleteMessages` methods. +- New #79: Add `answerInlineQuery` method, `InlineQueryResultsButton`, `InlineQueryResult*`, `InputMessageContent*` and + `LabeledPrice` types. - Chg #24: Move update methods to `Vjik\TelegramBot\Api\Method\Update` namespace, and update types to `Vjik\TelegramBot\Api\Type\Update` namespace. - Chg #30: Remove `TelegramRequestWithFilesInterface`.