Add editBotCommands for PATCH /me/commands, deprecate editBotInfo

The API no longer accepts PATCH /me: it answers "Path /me is not
recognized", so editBotInfo() fails, including for commands. Commands
now have their own endpoint, PATCH /me/commands (editMyCommands in the
official schema); bot name, description and photo are edited on the
MAX partner platform.

- Api::editBotCommands(BotCommand[]): BotCommandsInfo
- BotCommandsInfo model and ModelFactory::createBotCommandsInfo()
- editBotInfo() and BotPatch marked @deprecated
- README coverage map and docs updated
This commit is contained in:
Timofey
2026-09-28 00:08:35 +05:00
parent bf5219af7a
commit ca5ed4c100
9 changed files with 213 additions and 3 deletions
+56
View File
@@ -35,6 +35,8 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\PhotoAttachmentRequ
use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\ShareAttachmentRequest;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\StickerAttachmentRequest;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\VideoAttachmentRequest;
use BushlanovDev\MaxMessengerBot\Models\BotCommand;
use BushlanovDev\MaxMessengerBot\Models\BotCommandsInfo;
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
use BushlanovDev\MaxMessengerBot\Models\BotPatch;
use BushlanovDev\MaxMessengerBot\Models\Chat;
@@ -116,6 +118,8 @@ use RuntimeException;
#[UsesClass(ChatMembersList::class)]
#[UsesClass(ChatAdmin::class)]
#[UsesClass(BotPatch::class)]
#[UsesClass(BotCommand::class)]
#[UsesClass(BotCommandsInfo::class)]
#[UsesClass(ChatPatch::class)]
#[UsesClass(VideoAttachmentDetails::class)]
#[UsesClass(VideoUrls::class)]
@@ -1883,6 +1887,58 @@ final class ApiTest extends TestCase
$this->assertSame($expectedResult, $result);
}
#[Test]
public function editBotCommandsSendsCommandsToDedicatedEndpoint(): void
{
$rawResponseData = [
'commands' => [
['name' => 'start', 'description' => 'Start the bot'],
['name' => 'help', 'description' => null],
],
];
$expectedResult = new BotCommandsInfo([
new BotCommand('start', 'Start the bot'),
new BotCommand('help', null),
]);
$this->clientMock
->expects($this->once())
->method('request')
->with('PATCH', '/me/commands', [], $rawResponseData)
->willReturn($rawResponseData);
$this->modelFactoryMock
->expects($this->once())
->method('createBotCommandsInfo')
->with($rawResponseData)
->willReturn($expectedResult);
$result = $this->api->editBotCommands([
new BotCommand('start', 'Start the bot'),
new BotCommand('help', null),
]);
$this->assertSame($expectedResult, $result);
}
#[Test]
public function editBotCommandsSendsAnEmptyList(): void
{
$this->clientMock
->expects($this->once())
->method('request')
->with('PATCH', '/me/commands', [], ['commands' => []])
->willReturn(['commands' => []]);
$this->modelFactoryMock
->expects($this->once())
->method('createBotCommandsInfo')
->with(['commands' => []])
->willReturn(new BotCommandsInfo([]));
$this->api->editBotCommands([]);
}
#[Test]
public function editBotInfoSendsCorrectPatchBody(): void
{
+19
View File
@@ -27,6 +27,7 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ShareAttachmentRequ
use BushlanovDev\MaxMessengerBot\Models\Attachments\PhotoAttachment;
use BushlanovDev\MaxMessengerBot\Models\Attachments\ShareAttachment;
use BushlanovDev\MaxMessengerBot\Models\BotCommand;
use BushlanovDev\MaxMessengerBot\Models\BotCommandsInfo;
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
use BushlanovDev\MaxMessengerBot\Models\Chat;
use BushlanovDev\MaxMessengerBot\Models\ChatList;
@@ -61,6 +62,7 @@ use Psr\Log\LoggerInterface;
#[CoversClass(ModelFactory::class)]
#[UsesClass(BotInfo::class)]
#[UsesClass(BotCommand::class)]
#[UsesClass(BotCommandsInfo::class)]
#[UsesClass(Result::class)]
#[UsesClass(Subscription::class)]
#[UsesClass(ArrayOf::class)]
@@ -171,6 +173,23 @@ final class ModelFactoryTest extends TestCase
$this->assertSame('help', $botInfo->commands[1]->name);
}
#[Test]
public function createBotCommandsInfoHydratesCommands(): void
{
$botCommands = $this->factory->createBotCommandsInfo([
'commands' => [
['name' => 'start', 'description' => 'Start the bot'],
['name' => 'help', 'description' => null],
],
]);
$this->assertInstanceOf(BotCommandsInfo::class, $botCommands);
$this->assertCount(2, $botCommands->commands);
$this->assertInstanceOf(BotCommand::class, $botCommands->commands[0]);
$this->assertSame('start', $botCommands->commands[0]->name);
$this->assertNull($botCommands->commands[1]->description);
}
#[Test]
public function createBotInfoHandlesNullCommands(): void
{
+48
View File
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Tests\Models;
use BushlanovDev\MaxMessengerBot\Attributes\ArrayOf;
use BushlanovDev\MaxMessengerBot\Models\BotCommand;
use BushlanovDev\MaxMessengerBot\Models\BotCommandsInfo;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(BotCommandsInfo::class)]
#[UsesClass(BotCommand::class)]
#[UsesClass(ArrayOf::class)]
final class BotCommandsInfoTest extends TestCase
{
#[Test]
public function canBeCreatedFromArray(): void
{
$info = BotCommandsInfo::fromArray([
'commands' => [
['name' => 'start', 'description' => 'Start the bot'],
],
]);
$this->assertCount(1, $info->commands);
$this->assertInstanceOf(BotCommand::class, $info->commands[0]);
$this->assertSame('start', $info->commands[0]->name);
$this->assertSame('Start the bot', $info->commands[0]->description);
}
#[Test]
public function commandsAreNullWhenTheBotHasNone(): void
{
$this->assertNull(BotCommandsInfo::fromArray([])->commands);
}
#[Test]
public function toArraySerializesCommands(): void
{
$info = new BotCommandsInfo([new BotCommand('help', 'Help')]);
$this->assertSame(['commands' => [['name' => 'help', 'description' => 'Help']]], $info->toArray());
}
}