mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-10-06 20:10:31 +00:00
dd00b4c5e6
The schema lists post_id as required, but the official TypeScript client types it as `string | null`. A null would fail with a TypeError and, unlike an unknown update type, TypeError is not caught while parsing updates.
51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Updates;
|
|
|
|
use BushlanovDev\MaxMessengerBot\Enums\UpdateType;
|
|
use BushlanovDev\MaxMessengerBot\Models\Updates\CommentRemovedUpdate;
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
#[CoversClass(CommentRemovedUpdate::class)]
|
|
final class CommentRemovedUpdateTest extends TestCase
|
|
{
|
|
#[Test]
|
|
public function canBeCreatedFromArray(): void
|
|
{
|
|
$update = CommentRemovedUpdate::fromArray([
|
|
'update_type' => UpdateType::CommentRemoved->value,
|
|
'timestamp' => 1678886400000,
|
|
'message_id' => 'mid.comment',
|
|
'chat_id' => -100,
|
|
'user_id' => 42,
|
|
'post_id' => 'mid.post',
|
|
]);
|
|
|
|
$this->assertSame(UpdateType::CommentRemoved, $update->updateType);
|
|
$this->assertSame('mid.comment', $update->messageId);
|
|
$this->assertSame(-100, $update->chatId);
|
|
$this->assertSame(42, $update->userId);
|
|
$this->assertSame('mid.post', $update->postId);
|
|
}
|
|
|
|
#[Test]
|
|
public function postIdMayBeNull(): void
|
|
{
|
|
// The official TypeScript client types post_id as `string | null`
|
|
$update = CommentRemovedUpdate::fromArray([
|
|
'update_type' => UpdateType::CommentRemoved->value,
|
|
'timestamp' => 1678886400000,
|
|
'message_id' => 'mid.comment',
|
|
'chat_id' => -100,
|
|
'user_id' => 42,
|
|
'post_id' => null,
|
|
]);
|
|
|
|
$this->assertNull($update->postId);
|
|
}
|
|
}
|