-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
setStickerSetThumbnail
method (#61)
- Loading branch information
Showing
5 changed files
with
145 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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vjik\TelegramBot\Api\Method\Sticker; | ||
|
||
use Vjik\TelegramBot\Api\ParseResult\ValueHelper; | ||
use Vjik\TelegramBot\Api\Request\HttpMethod; | ||
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface; | ||
use Vjik\TelegramBot\Api\Type\InputFile; | ||
|
||
/** | ||
* @see https://core.telegram.org/bots/api#setstickersetthumbnail | ||
*/ | ||
final readonly class SetStickerSetThumbnail implements TelegramRequestWithResultPreparingInterface | ||
{ | ||
public function __construct( | ||
private string $name, | ||
private int $userId, | ||
private string $format, | ||
private InputFile|string|null $thumbnail = null, | ||
) { | ||
} | ||
|
||
public function getHttpMethod(): HttpMethod | ||
{ | ||
return HttpMethod::POST; | ||
} | ||
|
||
public function getApiMethod(): string | ||
{ | ||
return 'setStickerSetThumbnail'; | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
return array_filter( | ||
[ | ||
'name' => $this->name, | ||
'user_id' => $this->userId, | ||
'thumbnail' => $this->thumbnail, | ||
'format' => $this->format, | ||
], | ||
static fn(mixed $value): bool => $value !== null, | ||
); | ||
} | ||
|
||
public function prepareResult(mixed $result): true | ||
{ | ||
ValueHelper::assertTrueResult($result); | ||
return $result; | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vjik\TelegramBot\Api\Tests\Method\Sticker; | ||
|
||
use HttpSoft\Message\StreamFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Vjik\TelegramBot\Api\Method\Sticker\SetStickerSetThumbnail; | ||
use Vjik\TelegramBot\Api\Request\HttpMethod; | ||
use Vjik\TelegramBot\Api\Type\InputFile; | ||
|
||
final class SetStickerSetThumbnailTest extends TestCase | ||
{ | ||
public function testBase(): void | ||
{ | ||
$method = new SetStickerSetThumbnail('animals_by_my_bot', 123, 'static'); | ||
|
||
$this->assertSame(HttpMethod::POST, $method->getHttpMethod()); | ||
$this->assertSame('setStickerSetThumbnail', $method->getApiMethod()); | ||
$this->assertSame( | ||
[ | ||
'name' => 'animals_by_my_bot', | ||
'user_id' => 123, | ||
'format' => 'static', | ||
], | ||
$method->getData(), | ||
); | ||
} | ||
|
||
public function testFull(): void | ||
{ | ||
$file = new InputFile((new StreamFactory())->createStream()); | ||
$method = new SetStickerSetThumbnail('animals_by_my_bot', 123, 'static', $file); | ||
|
||
$this->assertSame(HttpMethod::POST, $method->getHttpMethod()); | ||
$this->assertSame('setStickerSetThumbnail', $method->getApiMethod()); | ||
$this->assertSame( | ||
[ | ||
'name' => 'animals_by_my_bot', | ||
'user_id' => 123, | ||
'thumbnail' => $file, | ||
'format' => 'static', | ||
], | ||
$method->getData(), | ||
); | ||
} | ||
|
||
public function testPrepareResult(): void | ||
{ | ||
$method = new SetStickerSetThumbnail('animals_by_my_bot', 123, 'static'); | ||
|
||
$preparedResult = $method->prepareResult(true); | ||
|
||
$this->assertTrue($preparedResult); | ||
} | ||
} |
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