-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from TelegramBot/feature/botCommands
Add BotCommand type, setMyCommands and getMyCommands methods
- Loading branch information
Showing
4 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace TelegramBot\Api\Types; | ||
|
||
abstract class ArrayOfBotCommand | ||
{ | ||
public static function fromResponse($data) | ||
{ | ||
$arrayOfBotCommand = []; | ||
foreach ($data as $botCommand) { | ||
$arrayOfBotCommand[] = BotCommand::fromResponse($botCommand); | ||
} | ||
|
||
return $arrayOfBotCommand; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace TelegramBot\Api\Types; | ||
|
||
use TelegramBot\Api\BaseType; | ||
use TelegramBot\Api\TypeInterface; | ||
|
||
class BotCommand extends BaseType implements TypeInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var array | ||
*/ | ||
static protected $requiredParams = ['command', 'description']; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var array | ||
*/ | ||
static protected $map = [ | ||
'command' => true, | ||
'description' => true, | ||
]; | ||
|
||
/** | ||
* Text of the command, 1-32 characters. Can contain only lowercase English letters, digits and underscores. | ||
* | ||
* @var string | ||
*/ | ||
protected $command; | ||
|
||
/** | ||
* Description of the command, 3-256 characters. | ||
* | ||
* @var string | ||
*/ | ||
protected $description; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCommand() | ||
{ | ||
return $this->command; | ||
} | ||
|
||
/** | ||
* @param string $command | ||
*/ | ||
public function setCommand($command) | ||
{ | ||
$this->command = $command; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDescription() | ||
{ | ||
return $this->description; | ||
} | ||
|
||
/** | ||
* @param string $description | ||
*/ | ||
public function setDescription($description) | ||
{ | ||
$this->description = $description; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace TelegramBot\Api\Test; | ||
|
||
use TelegramBot\Api\Types\BotCommand; | ||
|
||
class BotCommandTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testSetCommand() | ||
{ | ||
$item = new BotCommand(); | ||
$item->setCommand('start'); | ||
$this->assertAttributeEquals('start', 'command', $item); | ||
} | ||
|
||
public function testGetCommand() | ||
{ | ||
$item = new BotCommand(); | ||
$item->setCommand('start'); | ||
$this->assertEquals('start', $item->getCommand()); | ||
} | ||
|
||
public function testSetDescription() | ||
{ | ||
$item = new BotCommand(); | ||
$item->setDescription('This is a start command!'); | ||
$this->assertAttributeEquals('This is a start command!', 'description', $item); | ||
} | ||
|
||
public function testGetDescription() | ||
{ | ||
$item = new BotCommand(); | ||
$item->setDescription('This is a start command!'); | ||
$this->assertEquals('This is a start command!', $item->getDescription()); | ||
} | ||
|
||
public function testFromResponse() | ||
{ | ||
$botCommand = BotCommand::fromResponse( | ||
[ | ||
'command' => 'start', | ||
'description' => 'This is a start command!', | ||
] | ||
); | ||
|
||
$this->assertInstanceOf('\TelegramBot\Api\Types\BotCommand', $botCommand); | ||
$this->assertEquals('start', $botCommand->getCommand()); | ||
$this->assertEquals('This is a start command!', $botCommand->getDescription()); | ||
} | ||
} |