Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TransactionPartnerTelegramAds type #91

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Telegram Bot API for PHP Change Log

## 0.2.1 under development

- New #91: Add `TransactionPartnerTelegramAds` type.

## 0.2.0 June 29, 2024

- New #16: Add `sendContact` method.
Expand Down
2 changes: 1 addition & 1 deletion src/Method/SendDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @see https://core.telegram.org/bots/api#senddocument
*/
final readonly class SendDocument implements TelegramRequestWithResultPreparingInterface
final readonly class SendDocument implements TelegramRequestWithResultPreparingInterface
{
/**
* @param MessageEntity[]|null $captionEntities
Expand Down
1 change: 1 addition & 0 deletions src/Type/Payment/TransactionPartnerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static function fromTelegramResult(mixed $result): TransactionPartner
ValueHelper::assertArrayResult($result);
return match (ValueHelper::getString($result, 'type')) {
'fragment' => TransactionPartnerFragment::fromTelegramResult($result),
'telegram_ads' => TransactionPartnerTelegramAds::fromTelegramResult($result),
'user' => TransactionPartnerUser::fromTelegramResult($result),
'other' => TransactionPartnerOther::fromTelegramResult($result),
default => throw new TelegramParseResultException('Unknown transaction partner type.'),
Expand Down
24 changes: 24 additions & 0 deletions src/Type/Payment/TransactionPartnerTelegramAds.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Type\Payment;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;

/**
* @see https://core.telegram.org/bots/api#transactionpartnertelegramads
*/
final readonly class TransactionPartnerTelegramAds implements TransactionPartner
{
public function getType(): string
{
return 'telegram_ads';
}

public static function fromTelegramResult(mixed $result): self
{
ValueHelper::assertArrayResult($result);
return new self();
}
}
7 changes: 7 additions & 0 deletions tests/Type/Payment/TransactionPartnerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Vjik\TelegramBot\Api\Type\Payment\TransactionPartnerFactory;
use Vjik\TelegramBot\Api\Type\Payment\TransactionPartnerFragment;
use Vjik\TelegramBot\Api\Type\Payment\TransactionPartnerOther;
use Vjik\TelegramBot\Api\Type\Payment\TransactionPartnerTelegramAds;
use Vjik\TelegramBot\Api\Type\Payment\TransactionPartnerUser;

final class TransactionPartnerFactoryTest extends TestCase
Expand All @@ -23,6 +24,12 @@ public static function dataBase(): array
'type' => 'fragment',
],
],
[
TransactionPartnerTelegramAds::class,
[
'type' => 'telegram_ads',
],
],
[
TransactionPartnerUser::class,
[
Expand Down
35 changes: 35 additions & 0 deletions tests/Type/Payment/TransactionPartnerTelegramAdsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Type\Payment;

use PHPUnit\Framework\TestCase;
use Vjik\TelegramBot\Api\ParseResult\TelegramParseResultException;
use Vjik\TelegramBot\Api\Type\Payment\TransactionPartnerTelegramAds;

final class TransactionPartnerTelegramAdsTest extends TestCase
{
public function testBase(): void
{
$object = new TransactionPartnerTelegramAds();

$this->assertSame('telegram_ads', $object->getType());
}

public function testFromTelegramResult(): void
{
$object = TransactionPartnerTelegramAds::fromTelegramResult([
'type' => 'telegram_ads',
]);

$this->assertSame('telegram_ads', $object->getType());
}

public function testFromTelegramResultWithInvalidResult(): void
{
$this->expectException(TelegramParseResultException::class);
$this->expectExceptionMessage('Expected result as array. Got "string".');
TransactionPartnerTelegramAds::fromTelegramResult('hello');
}
}
Loading