Skip to content

Fixes issue #1303 #1304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Entities/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(array $data, string $bot_username = '')
*
* @return array
*/
public function jsonSerialize()
public function jsonSerialize(): array
{
return $this->getRawData();
}
Expand Down Expand Up @@ -161,6 +161,7 @@ public function __call($method, $args)
// Limit setters to specific classes.
if ($this instanceof InlineEntity || $this instanceof InputMedia || $this instanceof Keyboard || $this instanceof KeyboardButton) {
$this->$property_name = $args[0];
$this->raw_data[$property_name] = $args[0];

return $this;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/Unit/Entities/KeyboardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,23 @@ public function testKeyboardAddRows(): void
$keyboard = $keyboard_obj->getProperty('keyboard');
self::assertSame('Button Text 4', $keyboard[2][0]->getText());
}

public function testSetterMethods(): void
{
$keyboard = (new Keyboard(
[
['text' => 'One']
]
))->setResizeKeyboard(true);

$array = json_decode($keyboard->toJson(), true);

$this->assertIsArray($array);

$this->assertArrayHasKey('keyboard', $array);
$this->assertArrayHasKey('resize_keyboard', $array);

$this->assertIsArray($array['keyboard']);
$this->assertEquals(true, $array['resize_keyboard']);
}
}