-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #465 add Giveaway as defined in api 7.0
- Loading branch information
1 parent
d9d4fe5
commit 6ebd05c
Showing
6 changed files
with
258 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,39 @@ | ||
<?php | ||
|
||
namespace TelegramBot\Api\Test\Types; | ||
|
||
use TelegramBot\Api\Types\Chat; | ||
use TelegramBot\Api\Types\ArrayOfChat; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ArrayOfChatTest extends TestCase | ||
{ | ||
public function testFromResponse() | ||
{ | ||
$items = ArrayOfChat::fromResponse([ | ||
[ | ||
'id' => 123456789, | ||
'type' => 'group', | ||
], | ||
[ | ||
'id' => 123456788, | ||
'type' => 'private', | ||
] | ||
]); | ||
|
||
$expected = [ | ||
Chat::fromResponse([ | ||
'id' => 123456789, | ||
'type' => 'group', | ||
]), | ||
Chat::fromResponse([ | ||
'id' => 123456788, | ||
'type' => 'private', | ||
]) | ||
]; | ||
|
||
foreach ($items as $key => $item) { | ||
$this->assertEquals($expected[$key], $item); | ||
} | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace TelegramBot\Api\Test\Types; | ||
|
||
use TelegramBot\Api\Test\AbstractTypeTest; | ||
use TelegramBot\Api\Types\GiveawayCompleted; | ||
|
||
class GiveawayCompletedTest extends AbstractTypeTest | ||
{ | ||
protected static function getType() | ||
{ | ||
return GiveawayCompleted::class; | ||
} | ||
|
||
public static function getMinResponse() | ||
{ | ||
return [ | ||
'winner_count' => 1 | ||
]; | ||
} | ||
|
||
public static function getFullResponse() | ||
{ | ||
return [ | ||
'winner_count' => 1, | ||
'unclaimed_prize_count' => 1, | ||
'giveaway_message' => MessageTest::getMinResponse() | ||
]; | ||
} | ||
|
||
protected function assertMinItem($item) | ||
{ | ||
$this->assertEquals(1, $item->getWinnerCount()); | ||
} | ||
|
||
protected function assertFullItem($item) | ||
{ | ||
$this->assertEquals(1, $item->getWinnerCount()); | ||
$this->assertEquals(1, $item->getUnclaimedPrizeCount()); | ||
$this->assertEquals(MessageTest::createMinInstance(), $item->getGiveawayMessage()); | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace TelegramBot\Api\Test\Types; | ||
|
||
use TelegramBot\Api\Test\AbstractTypeTest; | ||
use TelegramBot\Api\Types\GiveawayCreated; | ||
|
||
class GiveawayCreatedTest extends AbstractTypeTest | ||
{ | ||
protected static function getType() | ||
{ | ||
return GiveawayCreated::class; | ||
} | ||
|
||
public static function getMinResponse() | ||
{ | ||
return []; | ||
} | ||
|
||
public static function getFullResponse() | ||
{ | ||
return []; | ||
} | ||
|
||
protected function assertMinItem($item) | ||
{ | ||
} | ||
|
||
protected function assertFullItem($item) | ||
{ | ||
} | ||
} |
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,66 @@ | ||
<?php | ||
|
||
namespace TelegramBot\Api\Test\Types; | ||
|
||
use TelegramBot\Api\Types\Giveaway; | ||
use TelegramBot\Api\Test\AbstractTypeTest; | ||
|
||
class GiveawayTest extends AbstractTypeTest | ||
{ | ||
protected static function getType() | ||
{ | ||
return Giveaway::class; | ||
} | ||
|
||
public static function getMinResponse() | ||
{ | ||
return [ | ||
'chats' => [ | ||
ChatTest::getMinResponse() | ||
], | ||
'winners_selection_date' => 1682343643, | ||
'winner_count' => 1, | ||
]; | ||
} | ||
|
||
public static function getFullResponse() | ||
{ | ||
return [ | ||
'chats' => [ | ||
ChatTest::getMinResponse() | ||
], | ||
'winners_selection_date' => 1682343643, | ||
'winner_count' => 1, | ||
'only_new_members' => true, | ||
'has_public_winners' => true, | ||
'prize_description' => 'prize', | ||
'country_codes' => ['RU'], | ||
'premium_subscription_month_count' => 1, | ||
]; | ||
} | ||
|
||
protected function assertMinItem($item) | ||
{ | ||
$this->assertEquals(1, $item->getWinnerCount()); | ||
$this->assertEquals(1682343643, $item->getWinnersSelectionDate()); | ||
$this->assertIsArray($item->getChats()); | ||
|
||
$this->assertNull($item->getOnlyNewMembers()); | ||
$this->assertNull($item->getHasPublicWinners()); | ||
$this->assertNull($item->getPrizeDescription()); | ||
$this->assertNull($item->getCountryCodes()); | ||
$this->assertNull($item->getPremiumSubscriptionMonthCount()); | ||
} | ||
|
||
protected function assertFullItem($item) | ||
{ | ||
$this->assertEquals(1, $item->getWinnerCount()); | ||
$this->assertEquals(1682343643, $item->getWinnersSelectionDate()); | ||
$this->assertIsArray($item->getChats()); | ||
$this->assertTrue($item->getOnlyNewMembers()); | ||
$this->assertTrue($item->getHasPublicWinners()); | ||
$this->assertEquals('prize', $item->getPrizeDescription()); | ||
$this->assertIsArray($item->getCountryCodes()); | ||
$this->assertEquals(1, $item->getPremiumSubscriptionMonthCount()); | ||
} | ||
} |
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,74 @@ | ||
<?php | ||
|
||
namespace TelegramBot\Api\Test\Types; | ||
|
||
use TelegramBot\Api\Test\AbstractTypeTest; | ||
use TelegramBot\Api\Types\GiveawayWinners; | ||
|
||
class GiveawayWinnersTest extends AbstractTypeTest | ||
{ | ||
protected static function getType() | ||
{ | ||
return GiveawayWinners::class; | ||
} | ||
|
||
public static function getMinResponse() | ||
{ | ||
return [ | ||
'chat' => ChatTest::getMinResponse(), | ||
'giveaway_message_id' => 1, | ||
'winners_selection_date' => 1682343643, | ||
'winner_count' => 1, | ||
'winners' => [ | ||
UserTest::getMinResponse() | ||
], | ||
]; | ||
} | ||
|
||
public static function getFullResponse() | ||
{ | ||
return [ | ||
'chat' => ChatTest::getMinResponse(), | ||
'giveaway_message_id' => 1, | ||
'winners_selection_date' => 1682343643, | ||
'winner_count' => 1, | ||
'winners' => [ | ||
UserTest::getMinResponse() | ||
], | ||
'additional_chat_count' => 1, | ||
'premium_subscription_month_count' => 1, | ||
'unclaimed_prize_count' => 0, | ||
'only_new_members' => true, | ||
'was_refunded' => true, | ||
'prize_description' => 'prize', | ||
]; | ||
} | ||
|
||
protected function assertMinItem($item) | ||
{ | ||
$this->assertEquals(1, $item->getGiveawayMessageId()); | ||
$this->assertEquals(1682343643, $item->getWinnersSelectionDate()); | ||
$this->assertEquals(1, $item->getWinnerCount()); | ||
$this->assertEquals([UserTest::createMinInstance()], $item->getWinners()); | ||
$this->assertNull($item->getAdditionalChatCount()); | ||
$this->assertNull($item->getPremiumSubscriptionMonthCount()); | ||
$this->assertNull($item->getUnclaimedPrizeCount()); | ||
$this->assertNull($item->getOnlyNewMembers()); | ||
$this->assertNull($item->getWasRefunded()); | ||
$this->assertNull($item->getPrizeDescription()); | ||
} | ||
|
||
protected function assertFullItem($item) | ||
{ | ||
$this->assertEquals(1, $item->getGiveawayMessageId()); | ||
$this->assertEquals(1682343643, $item->getWinnersSelectionDate()); | ||
$this->assertEquals(1, $item->getWinnerCount()); | ||
$this->assertEquals([UserTest::createMinInstance()], $item->getWinners()); | ||
$this->assertEquals(1, $item->getAdditionalChatCount()); | ||
$this->assertEquals(1, $item->getPremiumSubscriptionMonthCount()); | ||
$this->assertEquals(0, $item->getUnclaimedPrizeCount()); | ||
$this->assertTrue($item->getOnlyNewMembers()); | ||
$this->assertTrue($item->getWasRefunded()); | ||
$this->assertEquals('prize', $item->getPrizeDescription()); | ||
} | ||
} |