mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-08-20 09:27:11 +00:00
82 lines
2.5 KiB
PHP
82 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace BushlanovDev\MaxMessengerBot\Tests;
|
|
|
|
use BushlanovDev\MaxMessengerBot\ModelFactory;
|
|
use BushlanovDev\MaxMessengerBot\Models\BotCommand;
|
|
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use PHPUnit\Framework\Attributes\UsesClass;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
#[CoversClass(ModelFactory::class)]
|
|
#[UsesClass(BotInfo::class)]
|
|
#[UsesClass(BotCommand::class)]
|
|
final class ModelFactoryTest extends TestCase
|
|
{
|
|
private ModelFactory $factory;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->factory = new ModelFactory();
|
|
}
|
|
|
|
#[Test]
|
|
public function createBotInfoCorrectlyHydratesCommands(): void
|
|
{
|
|
$rawData = [
|
|
'user_id' => 12345,
|
|
'first_name' => 'Test',
|
|
'last_name' => 'Bot',
|
|
'username' => 'test_bot',
|
|
'is_bot' => true,
|
|
'last_activity_time' => 1678886400000,
|
|
'description' => 'A test bot.',
|
|
'avatar_url' => 'http://example.com/avatar.jpg',
|
|
'full_avatar_url' => 'http://example.com/full_avatar.jpg',
|
|
'commands' => [
|
|
['name' => 'start', 'description' => 'Start the bot'],
|
|
['name' => 'help', 'description' => 'Show help'],
|
|
],
|
|
];
|
|
|
|
$botInfo = $this->factory->createBotInfo($rawData);
|
|
|
|
$this->assertInstanceOf(BotInfo::class, $botInfo);
|
|
$this->assertSame(12345, $botInfo->user_id);
|
|
|
|
$this->assertIsArray($botInfo->commands);
|
|
$this->assertCount(2, $botInfo->commands);
|
|
$this->assertInstanceOf(BotCommand::class, $botInfo->commands[0]);
|
|
$this->assertSame('start', $botInfo->commands[0]->name);
|
|
$this->assertInstanceOf(BotCommand::class, $botInfo->commands[1]);
|
|
$this->assertSame('help', $botInfo->commands[1]->name);
|
|
}
|
|
|
|
#[Test]
|
|
public function createBotInfoHandlesNullCommands(): void
|
|
{
|
|
$rawData = [
|
|
'user_id' => 12345,
|
|
'first_name' => 'Test',
|
|
'last_name' => null,
|
|
'username' => 'test_bot',
|
|
'is_bot' => true,
|
|
'last_activity_time' => 1678886400000,
|
|
'description' => null,
|
|
'avatar_url' => null,
|
|
'full_avatar_url' => null,
|
|
'commands' => null,
|
|
];
|
|
|
|
$botInfo = $this->factory->createBotInfo($rawData);
|
|
|
|
$this->assertInstanceOf(BotInfo::class, $botInfo);
|
|
$this->assertNull($botInfo->commands);
|
|
}
|
|
}
|