mirror of
https://github.com/danog/tg-file-decoder.git
synced 2024-11-26 12:24:40 +01:00
Fixup
This commit is contained in:
parent
9d9c253848
commit
34338dba16
@ -11,6 +11,7 @@
|
||||
>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
<directory name="tests" />
|
||||
<ignoreFiles>
|
||||
<directory name="vendor" />
|
||||
</ignoreFiles>
|
||||
|
@ -98,6 +98,30 @@ enum FileIdType: int
|
||||
case SIZE = 17;
|
||||
case NONE = 18;
|
||||
|
||||
public static function fromBotApiType(string $type): self
|
||||
{
|
||||
return match ($type) {
|
||||
'thumbnail' => self::THUMBNAIL,
|
||||
'profile_photo' => self::PROFILE_PHOTO,
|
||||
'photo' => self::PHOTO,
|
||||
'voice' => self::VOICE,
|
||||
'video' => self::VIDEO,
|
||||
'document' => self::DOCUMENT,
|
||||
'encrypted' => self::ENCRYPTED,
|
||||
'temp' => self::TEMP,
|
||||
'sticker' => self::STICKER,
|
||||
'audio' => self::AUDIO,
|
||||
'animation' => self::ANIMATION,
|
||||
'encrypted_thumbnail' => self::ENCRYPTED_THUMBNAIL,
|
||||
'wallpaper' => self::WALLPAPER,
|
||||
'video_note' => self::VIDEO_NOTE,
|
||||
'secure_raw' => self::SECURE_RAW,
|
||||
'secure' => self::SECURE,
|
||||
'background' => self::BACKGROUND,
|
||||
'size' => self::SIZE,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert file ID type to unique file ID type.
|
||||
*/
|
||||
|
@ -4,38 +4,36 @@ namespace danog\Decoder\Test;
|
||||
|
||||
use CURLFile;
|
||||
use danog\Decoder\FileId;
|
||||
use danog\Decoder\FileIdType;
|
||||
use danog\Decoder\UniqueFileId;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use const danog\Decoder\FULL_UNIQUE_MAP;
|
||||
use const danog\Decoder\TYPES_IDS;
|
||||
|
||||
/** @api */
|
||||
class IntegrationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $type Expected type
|
||||
*
|
||||
* @dataProvider provideFileIdsAndType
|
||||
*/
|
||||
public function testAll(string $type, string $fileIdStr, string $uniqueFileIdStr)
|
||||
public function testAll(FileIdType $type, string $fileIdStr, string $uniqueFileIdStr): void
|
||||
{
|
||||
$fileId = FileId::fromBotAPI($fileIdStr);
|
||||
$this->assertSame($type, $fileId->getTypeName());
|
||||
$this->assertSame($type, $fileId->type);
|
||||
|
||||
$this->assertSame($fileIdStr, $fileId->getBotAPI());
|
||||
|
||||
$uniqueFileId = UniqueFileId::fromUniqueBotAPI($uniqueFileIdStr);
|
||||
$this->assertSame(FULL_UNIQUE_MAP[TYPES_IDS[$type]], $uniqueFileId->getType());
|
||||
$this->assertSame($type->toUnique(), $uniqueFileId->type);
|
||||
$this->assertSame($uniqueFileIdStr, $uniqueFileId->getUniqueBotAPI());
|
||||
|
||||
$this->assertSame($uniqueFileIdStr, $fileId->getUnique()->getUniqueBotAPI());
|
||||
}
|
||||
|
||||
/** @psalm-suppress MixedArrayAccess, MixedAssignment, PossiblyInvalidArgument, MixedArgument */
|
||||
public function provideFileIdsAndType(): \Generator
|
||||
{
|
||||
foreach (['CAADBAADwwADmFmqDf6xBrPTReqHFgQ', 'CAACAgQAAxkBAAIC4l9CWDGzVUcDejU0TETLWbOdfsCoAALDAAOYWaoN_rEGs9NF6ocbBA', 'CAADBAADwwADmFmqDf6xBrPTReqHAg'] as $fileId) {
|
||||
yield [
|
||||
'sticker',
|
||||
FileIdType::STICKER,
|
||||
$fileId,
|
||||
'AgADwwADmFmqDQ'
|
||||
];
|
||||
@ -44,14 +42,22 @@ class IntegrationTest extends TestCase
|
||||
$dest = \getenv('DEST');
|
||||
$token = \getenv('TOKEN');
|
||||
foreach ($this->provideChats() as $chat) {
|
||||
/**
|
||||
* @var array{
|
||||
* small_file_id: string,
|
||||
* small_file_unique_id: string,
|
||||
* big_file_id: string,
|
||||
* big_file_unique_id: string
|
||||
* }
|
||||
*/
|
||||
$result = \json_decode(\file_get_contents("https://api.telegram.org/bot$token/getChat?chat_id=$chat"), true)['result']['photo'];
|
||||
yield [
|
||||
'profile_photo',
|
||||
FileIdType::PROFILE_PHOTO,
|
||||
$result['small_file_id'],
|
||||
$result['small_file_unique_id'],
|
||||
];
|
||||
yield [
|
||||
'profile_photo',
|
||||
FileIdType::fromBotApiType('profile_photo'),
|
||||
$result['big_file_id'],
|
||||
$result['big_file_unique_id'],
|
||||
];
|
||||
@ -78,14 +84,15 @@ class IntegrationTest extends TestCase
|
||||
$botResult = [$botResult];
|
||||
}
|
||||
foreach ($botResult as $subResult) {
|
||||
/** @var string $type */
|
||||
yield [
|
||||
$type,
|
||||
FileIdType::fromBotApiType($type),
|
||||
$subResult['file_id'],
|
||||
$subResult['file_unique_id']
|
||||
];
|
||||
if (isset($subResult['thumb'])) {
|
||||
yield [
|
||||
'thumbnail',
|
||||
FileIdType::fromBotApiType('thumbnail'),
|
||||
$subResult['thumb']['file_id'],
|
||||
$subResult['thumb']['file_unique_id']
|
||||
];
|
||||
@ -93,6 +100,10 @@ class IntegrationTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @psalm-suppress InvalidReturnStatement, InvalidReturnType
|
||||
* @return list<string>
|
||||
*/
|
||||
public function provideChats(): array
|
||||
{
|
||||
return [\getenv('DEST'), '@MadelineProto'];
|
||||
|
Loading…
Reference in New Issue
Block a user