Convert non-array update payloads to LogicException instead of TypeError

This commit is contained in:
Alex
2026-09-30 23:40:03 +03:00
parent bf5219af7a
commit 919970fa20
3 changed files with 108 additions and 2 deletions
+36
View File
@@ -249,4 +249,40 @@ final class WebhookHandlerTest extends TestCase
$this->assertFalse($handlerWasCalled);
}
public static function nonJsonObjectBodyProvider(): array
{
return [
'number' => ['123'],
'null' => ['null'],
'string' => ['"abc"'],
'boolean' => ['true'],
];
}
#[Test]
#[DataProvider('nonJsonObjectBodyProvider')]
public function handleSkipsBodyThatIsNotAJsonObject(string $payload): void
{
$request = $this->createMockRequest($payload, self::SECRET);
$this->loggerMock->expects($this->once())
->method('warning')
->with($this->stringContains('Failed to parse update: expected JSON object'));
$handlerWasCalled = false;
$this->dispatcher->addHandler(UpdateType::MessageCreated, function () use (&$handlerWasCalled) {
$handlerWasCalled = true;
});
$handler = new WebhookHandler(
$this->dispatcher,
new ModelFactory($this->loggerMock),
$this->loggerMock,
self::SECRET,
);
$handler->handle($request);
$this->assertFalse($handlerWasCalled);
}
}