Skip to content

Commit de24a76

Browse files
authored
Merge pull request #1395 from php-telegram-bot/1344-remove-keyboard-validations
Remove keyboard validations
2 parents 1c6380a + eaa40f3 commit de24a76

File tree

7 files changed

+9
-140
lines changed

7 files changed

+9
-140
lines changed

.github/workflows/tests.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
php: ['7.3', '7.4', '8.0', '8.1']
19+
php: ['7.3', '7.4', '8.0', '8.1', '8.2']
2020

2121
services:
2222
mariadb:
@@ -31,6 +31,12 @@ jobs:
3131
- name: Checkout
3232
uses: actions/checkout@v3
3333

34+
- name: Verify MariaDB connection
35+
run: |
36+
while ! mysqladmin ping -h127.0.0.1 -P3306 --silent; do
37+
sleep 1
38+
done
39+
3440
- name: Test migrations
3541
run: |
3642
git fetch origin 0.44.1 && git checkout FETCH_HEAD -- structure.sql

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
1212
### Changed
1313
### Deprecated
1414
### Removed
15+
- Keyboard validations (@noplanman)
1516
### Fixed
1617
- Fixed a bug where new incoming updates are not correctly passed to the Command object after the first time when getUpdates is used. (@uspilot) (#1384)
1718
### Security

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"\"vendor/bin/phpunit\""
6262
],
6363
"test-cov": [
64-
"\"vendor/bin/phpunit\" --coverage-clover clover.xml"
64+
"XDEBUG_MODE=coverage \"vendor/bin/phpunit\" --coverage-clover clover.xml"
6565
],
6666
"test-cov-upload": [
6767
"wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover clover.xml"

src/Entities/InlineKeyboardButton.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,34 +65,6 @@ public static function couldBe(array $data): bool
6565
);
6666
}
6767

68-
/**
69-
* {@inheritdoc}
70-
*/
71-
protected function validate(): void
72-
{
73-
if ($this->getProperty('text', '') === '') {
74-
throw new TelegramException('You must add some text to the button!');
75-
}
76-
77-
$num_params = 0;
78-
79-
foreach (['url', 'login_url', 'callback_data', 'web_app', 'callback_game', 'pay'] as $param) {
80-
if ($this->getProperty($param, '') !== '') {
81-
$num_params++;
82-
}
83-
}
84-
85-
foreach (['switch_inline_query', 'switch_inline_query_current_chat', 'switch_inline_query_chosen_chat'] as $param) {
86-
if ($this->getProperty($param) !== null) {
87-
$num_params++;
88-
}
89-
}
90-
91-
if ($num_params !== 1) {
92-
throw new TelegramException('You must use only one of these fields: url, login_url, callback_data, web_app, switch_inline_query, switch_inline_query_current_chat, switch_inline_query_chosen_chat, callback_game, pay!');
93-
}
94-
}
95-
9668
/**
9769
* {@inheritdoc}
9870
*/

src/Entities/KeyboardButton.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,6 @@ public static function couldBe(array $data): bool
7878
return array_key_exists('text', $data);
7979
}
8080

81-
/**
82-
* {@inheritdoc}
83-
*/
84-
protected function validate(): void
85-
{
86-
if ($this->getProperty('text', '') === '') {
87-
throw new TelegramException('You must add some text to the button!');
88-
}
89-
90-
// Make sure only 1 of the optional request fields is set.
91-
$field_count = array_filter([
92-
$this->getRequestUser(),
93-
$this->getRequestChat(),
94-
$this->getRequestContact(),
95-
$this->getRequestLocation(),
96-
$this->getRequestPoll(),
97-
$this->getWebApp(),
98-
]);
99-
if (count($field_count) > 1) {
100-
throw new TelegramException('You must use only one of these fields: request_user, request_chat, request_contact, request_location, request_poll, web_app!');
101-
}
102-
}
103-
10481
/**
10582
* {@inheritdoc}
10683
*/

tests/Unit/Entities/InlineKeyboardButtonTest.php

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -26,79 +26,6 @@
2626
*/
2727
class InlineKeyboardButtonTest extends TestCase
2828
{
29-
public function testInlineKeyboardButtonNoTextFail(): void
30-
{
31-
$this->expectException(TelegramException::class);
32-
$this->expectExceptionMessage('You must add some text to the button!');
33-
new InlineKeyboardButton([]);
34-
}
35-
36-
public function testInlineKeyboardButtonNoParameterFail(): void
37-
{
38-
$this->expectException(TelegramException::class);
39-
$this->expectExceptionMessage('You must use only one of these fields: url, login_url, callback_data, web_app, switch_inline_query, switch_inline_query_current_chat, switch_inline_query_chosen_chat, callback_game, pay!');
40-
new InlineKeyboardButton(['text' => 'message']);
41-
}
42-
43-
public function testInlineKeyboardButtonTooManyParametersFail(): void
44-
{
45-
$this->expectException(TelegramException::class);
46-
$this->expectExceptionMessage('You must use only one of these fields: url, login_url, callback_data, web_app, switch_inline_query, switch_inline_query_current_chat, switch_inline_query_chosen_chat, callback_game, pay!');
47-
$test_funcs = [
48-
function () {
49-
new InlineKeyboardButton([
50-
'text' => 'message',
51-
'url' => 'url_value',
52-
'callback_data' => 'callback_data_value',
53-
]);
54-
},
55-
function () {
56-
new InlineKeyboardButton([
57-
'text' => 'message',
58-
'url' => 'url_value',
59-
'switch_inline_query' => 'switch_inline_query_value',
60-
]);
61-
},
62-
function () {
63-
new InlineKeyboardButton([
64-
'text' => 'message',
65-
'callback_data' => 'callback_data_value',
66-
'switch_inline_query' => 'switch_inline_query_value',
67-
]);
68-
},
69-
function () {
70-
new InlineKeyboardButton([
71-
'text' => 'message',
72-
'callback_data' => 'callback_data_value',
73-
'switch_inline_query_current_chat' => 'switch_inline_query_current_chat_value',
74-
]);
75-
},
76-
function () {
77-
new InlineKeyboardButton([
78-
'text' => 'message',
79-
'callback_data' => 'callback_data_value',
80-
'switch_inline_query_chosen_chat' => new SwitchInlineQueryChosenChat([]),
81-
]);
82-
},
83-
function () {
84-
new InlineKeyboardButton([
85-
'text' => 'message',
86-
'callback_data' => 'callback_data_value',
87-
'callback_game' => new CallbackGame([]),
88-
]);
89-
},
90-
function () {
91-
new InlineKeyboardButton([
92-
'text' => 'message',
93-
'callback_data' => 'callback_data_value',
94-
'pay' => true,
95-
]);
96-
},
97-
];
98-
99-
$test_funcs[array_rand($test_funcs)]();
100-
}
101-
10229
public function testInlineKeyboardButtonSuccess(): void
10330
{
10431
new InlineKeyboardButton(['text' => 'message', 'url' => 'url_value']);

tests/Unit/Entities/KeyboardButtonTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,6 @@
2828
*/
2929
class KeyboardButtonTest extends TestCase
3030
{
31-
public function testKeyboardButtonNoTextFail(): void
32-
{
33-
$this->expectException(TelegramException::class);
34-
$this->expectExceptionMessage('You must add some text to the button!');
35-
new KeyboardButton([]);
36-
}
37-
38-
public function testKeyboardButtonTooManyParametersFail(): void
39-
{
40-
$this->expectException(TelegramException::class);
41-
$this->expectExceptionMessage('You must use only one of these fields: request_user, request_chat, request_contact, request_location, request_poll, web_app!');
42-
new KeyboardButton(['text' => 'message', 'request_contact' => true, 'request_location' => true]);
43-
}
44-
4531
public function testKeyboardButtonSuccess(): void
4632
{
4733
new KeyboardButton(['text' => 'message']);

0 commit comments

Comments
 (0)