-
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.
- Loading branch information
Showing
9 changed files
with
284 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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vjik\TelegramBot\Api\Method; | ||
|
||
use Vjik\TelegramBot\Api\Request\HttpMethod; | ||
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface; | ||
use Vjik\TelegramBot\Api\Type\UserChatBoosts; | ||
|
||
/** | ||
* @see https://core.telegram.org/bots/api#getuserchatboosts | ||
*/ | ||
final readonly class GetUserChatBoosts implements TelegramRequestWithResultPreparingInterface | ||
{ | ||
public function __construct( | ||
private int|string $chatId, | ||
private int $userId, | ||
) { | ||
} | ||
|
||
public function getHttpMethod(): HttpMethod | ||
{ | ||
return HttpMethod::GET; | ||
} | ||
|
||
public function getApiMethod(): string | ||
{ | ||
return 'getUserChatBoosts'; | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
return [ | ||
'chat_id' => $this->chatId, | ||
'user_id' => $this->userId, | ||
]; | ||
} | ||
|
||
public function prepareResult(mixed $result): UserChatBoosts | ||
{ | ||
return UserChatBoosts::fromTelegramResult($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
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vjik\TelegramBot\Api\Type; | ||
|
||
use Vjik\TelegramBot\Api\ParseResult\ValueHelper; | ||
|
||
/** | ||
* @see https://core.telegram.org/bots/api#userchatboosts | ||
*/ | ||
final readonly class UserChatBoosts | ||
{ | ||
/** | ||
* @param ChatBoost[] $boosts | ||
*/ | ||
public function __construct( | ||
public array $boosts, | ||
) { | ||
} | ||
|
||
public static function fromTelegramResult(mixed $result): self | ||
{ | ||
ValueHelper::assertArrayResult($result); | ||
return new self( | ||
ValueHelper::getArrayOfChatBoosts($result, 'boosts'), | ||
); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vjik\TelegramBot\Api\Tests\Method; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vjik\TelegramBot\Api\Method\GetUserChatBoosts; | ||
use Vjik\TelegramBot\Api\Request\HttpMethod; | ||
|
||
final class GetUserChatBoostsTest extends TestCase | ||
{ | ||
public function testBase(): void | ||
{ | ||
$method = new GetUserChatBoosts(1, 2); | ||
|
||
$this->assertSame(HttpMethod::GET, $method->getHttpMethod()); | ||
$this->assertSame('getUserChatBoosts', $method->getApiMethod()); | ||
$this->assertSame( | ||
[ | ||
'chat_id' => 1, | ||
'user_id' => 2, | ||
], | ||
$method->getData() | ||
); | ||
} | ||
|
||
public function testPrepareResult(): void | ||
{ | ||
$method = new GetUserChatBoosts(1, 2); | ||
|
||
$preparedResult = $method->prepareResult([ | ||
'boosts' => [], | ||
]); | ||
|
||
$this->assertSame([], $preparedResult->boosts); | ||
} | ||
} |
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
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vjik\TelegramBot\Api\Tests\Type; | ||
|
||
use DateTimeImmutable; | ||
use PHPUnit\Framework\TestCase; | ||
use Vjik\TelegramBot\Api\Type\ChatBoost; | ||
use Vjik\TelegramBot\Api\Type\ChatBoostSourcePremium; | ||
use Vjik\TelegramBot\Api\Type\User; | ||
use Vjik\TelegramBot\Api\Type\UserChatBoosts; | ||
|
||
final class UserChatBoostsTest extends TestCase | ||
{ | ||
public function testBase(): void | ||
{ | ||
$chatBoost = new ChatBoost( | ||
'b1', | ||
new DateTimeImmutable(), | ||
new DateTimeImmutable(), | ||
new ChatBoostSourcePremium(new User(1, false, 'Sergei')), | ||
); | ||
$type = new UserChatBoosts([$chatBoost]); | ||
|
||
$this->assertSame([$chatBoost], $type->boosts); | ||
} | ||
|
||
public function testFromTelegramResult(): void | ||
{ | ||
$type = UserChatBoosts::fromTelegramResult([ | ||
'boosts' => [ | ||
[ | ||
'boost_id' => 'b1', | ||
'add_date' => 1619040000, | ||
'expiration_date' => 1619040001, | ||
'source' => [ | ||
'source' => 'premium', | ||
'user' => [ | ||
'id' => 1, | ||
'is_bot' => false, | ||
'first_name' => 'Sergei', | ||
], | ||
], | ||
], | ||
], | ||
]); | ||
|
||
$this->assertCount(1, $type->boosts); | ||
$this->assertSame('b1', $type->boosts[0]->boostId); | ||
} | ||
} |