Skip to content

Commit

Permalink
Merge pull request #1304 from php-telegram-bot/fix-1303
Browse files Browse the repository at this point in the history
Fixes issue #1303
  • Loading branch information
noplanman authored Mar 30, 2022
2 parents 956371f + 013bdc9 commit 1bf8f57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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']);
}
}

0 comments on commit 1bf8f57

Please sign in to comment.