Skip to content

Commit 1bf8f57

Browse files
authored
Merge pull request #1304 from php-telegram-bot/fix-1303
Fixes issue #1303
2 parents 956371f + 013bdc9 commit 1bf8f57

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Entities/Entity.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct(array $data, string $bot_username = '')
5757
*
5858
* @return array
5959
*/
60-
public function jsonSerialize()
60+
public function jsonSerialize(): array
6161
{
6262
return $this->getRawData();
6363
}
@@ -161,6 +161,7 @@ public function __call($method, $args)
161161
// Limit setters to specific classes.
162162
if ($this instanceof InlineEntity || $this instanceof InputMedia || $this instanceof Keyboard || $this instanceof KeyboardButton) {
163163
$this->$property_name = $args[0];
164+
$this->raw_data[$property_name] = $args[0];
164165

165166
return $this;
166167
}

tests/Unit/Entities/KeyboardTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,23 @@ public function testKeyboardAddRows(): void
186186
$keyboard = $keyboard_obj->getProperty('keyboard');
187187
self::assertSame('Button Text 4', $keyboard[2][0]->getText());
188188
}
189+
190+
public function testSetterMethods(): void
191+
{
192+
$keyboard = (new Keyboard(
193+
[
194+
['text' => 'One']
195+
]
196+
))->setResizeKeyboard(true);
197+
198+
$array = json_decode($keyboard->toJson(), true);
199+
200+
$this->assertIsArray($array);
201+
202+
$this->assertArrayHasKey('keyboard', $array);
203+
$this->assertArrayHasKey('resize_keyboard', $array);
204+
205+
$this->assertIsArray($array['keyboard']);
206+
$this->assertEquals(true, $array['resize_keyboard']);
207+
}
189208
}

0 commit comments

Comments
 (0)