mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-08-17 16:49:57 +00:00
Added DataAttachment & LinkedMessage & Markups
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Models\UserWithPhoto;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(UserWithPhoto::class)]
|
||||
final class UserWithPhotoTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function canBeCreatedFromArray(): void
|
||||
{
|
||||
$data = [
|
||||
'user_id' => 123,
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe',
|
||||
'username' => 'johndoe',
|
||||
'is_bot' => false,
|
||||
'last_activity_time' => 1678886400000,
|
||||
'description' => 'Description',
|
||||
'avatar_url' => 'https://example.com/avatar.jpg',
|
||||
'full_avatar_url' => 'https://example.com/full_avatar.jpg',
|
||||
];
|
||||
|
||||
$user = UserWithPhoto::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(UserWithPhoto::class, $user);
|
||||
$this->assertSame($data['user_id'], $user->userId);
|
||||
$this->assertSame($data['first_name'], $user->firstName);
|
||||
$this->assertSame($data['last_name'], $user->lastName);
|
||||
$this->assertSame($data['username'], $user->username);
|
||||
$this->assertSame($data['is_bot'], $user->isBot);
|
||||
$this->assertSame($data['last_activity_time'], $user->lastActivityTime);
|
||||
$this->assertSame($data['description'], $user->description);
|
||||
$this->assertSame($data['avatar_url'], $user->avatarUrl);
|
||||
$this->assertSame($data['full_avatar_url'], $user->fullAvatarUrl);
|
||||
|
||||
$array = $user->toArray();
|
||||
|
||||
$this->assertIsArray($array);
|
||||
$this->assertSame($data, $array);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function canBeCreatedFromArrayWithOptionalDataNull(): void
|
||||
{
|
||||
$data = [
|
||||
'user_id' => 123,
|
||||
'first_name' => 'John',
|
||||
'is_bot' => false,
|
||||
'last_activity_time' => 1678886400000,
|
||||
];
|
||||
|
||||
$user = UserWithPhoto::fromArray($data);
|
||||
|
||||
$this->assertInstanceOf(UserWithPhoto::class, $user);
|
||||
$this->assertSame($data['user_id'], $user->userId);
|
||||
$this->assertSame($data['first_name'], $user->firstName);
|
||||
$this->assertNull($user->lastName);
|
||||
$this->assertNull($user->username);
|
||||
$this->assertSame($data['is_bot'], $user->isBot);
|
||||
$this->assertSame($data['last_activity_time'], $user->lastActivityTime);
|
||||
$this->assertNull($user->description);
|
||||
$this->assertNull($user->avatarUrl);
|
||||
$this->assertNull($user->fullAvatarUrl);
|
||||
|
||||
$array = $user->toArray();
|
||||
|
||||
$this->assertIsArray($array);
|
||||
$array = array_filter($array, fn($item) => null !== $item);
|
||||
$this->assertSame($data, $array);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user