From b4d3b62b7ecade71803e75b156901e0b5b6999aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20L=C3=BCscher?= Date: Sat, 6 May 2023 11:20:23 +0200 Subject: [PATCH 1/3] Remove keyboard validations --- CHANGELOG.md | 1 + src/Entities/InlineKeyboardButton.php | 28 ------- src/Entities/KeyboardButton.php | 23 ------ .../Entities/InlineKeyboardButtonTest.php | 73 ------------------- tests/Unit/Entities/KeyboardButtonTest.php | 14 ---- 5 files changed, 1 insertion(+), 138 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 635e8ddb..0300da6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ### Changed ### Deprecated ### Removed +- Keyboard validations (@noplanman) ### Fixed - 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) ### Security diff --git a/src/Entities/InlineKeyboardButton.php b/src/Entities/InlineKeyboardButton.php index 89ebd769..e23439e5 100644 --- a/src/Entities/InlineKeyboardButton.php +++ b/src/Entities/InlineKeyboardButton.php @@ -65,34 +65,6 @@ public static function couldBe(array $data): bool ); } - /** - * {@inheritdoc} - */ - protected function validate(): void - { - if ($this->getProperty('text', '') === '') { - throw new TelegramException('You must add some text to the button!'); - } - - $num_params = 0; - - foreach (['url', 'login_url', 'callback_data', 'web_app', 'callback_game', 'pay'] as $param) { - if ($this->getProperty($param, '') !== '') { - $num_params++; - } - } - - foreach (['switch_inline_query', 'switch_inline_query_current_chat', 'switch_inline_query_chosen_chat'] as $param) { - if ($this->getProperty($param) !== null) { - $num_params++; - } - } - - if ($num_params !== 1) { - 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!'); - } - } - /** * {@inheritdoc} */ diff --git a/src/Entities/KeyboardButton.php b/src/Entities/KeyboardButton.php index e3dd55f4..d735a32d 100644 --- a/src/Entities/KeyboardButton.php +++ b/src/Entities/KeyboardButton.php @@ -78,29 +78,6 @@ public static function couldBe(array $data): bool return array_key_exists('text', $data); } - /** - * {@inheritdoc} - */ - protected function validate(): void - { - if ($this->getProperty('text', '') === '') { - throw new TelegramException('You must add some text to the button!'); - } - - // Make sure only 1 of the optional request fields is set. - $field_count = array_filter([ - $this->getRequestUser(), - $this->getRequestChat(), - $this->getRequestContact(), - $this->getRequestLocation(), - $this->getRequestPoll(), - $this->getWebApp(), - ]); - if (count($field_count) > 1) { - throw new TelegramException('You must use only one of these fields: request_user, request_chat, request_contact, request_location, request_poll, web_app!'); - } - } - /** * {@inheritdoc} */ diff --git a/tests/Unit/Entities/InlineKeyboardButtonTest.php b/tests/Unit/Entities/InlineKeyboardButtonTest.php index 6314d793..384430aa 100644 --- a/tests/Unit/Entities/InlineKeyboardButtonTest.php +++ b/tests/Unit/Entities/InlineKeyboardButtonTest.php @@ -26,79 +26,6 @@ */ class InlineKeyboardButtonTest extends TestCase { - public function testInlineKeyboardButtonNoTextFail(): void - { - $this->expectException(TelegramException::class); - $this->expectExceptionMessage('You must add some text to the button!'); - new InlineKeyboardButton([]); - } - - public function testInlineKeyboardButtonNoParameterFail(): void - { - $this->expectException(TelegramException::class); - $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!'); - new InlineKeyboardButton(['text' => 'message']); - } - - public function testInlineKeyboardButtonTooManyParametersFail(): void - { - $this->expectException(TelegramException::class); - $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!'); - $test_funcs = [ - function () { - new InlineKeyboardButton([ - 'text' => 'message', - 'url' => 'url_value', - 'callback_data' => 'callback_data_value', - ]); - }, - function () { - new InlineKeyboardButton([ - 'text' => 'message', - 'url' => 'url_value', - 'switch_inline_query' => 'switch_inline_query_value', - ]); - }, - function () { - new InlineKeyboardButton([ - 'text' => 'message', - 'callback_data' => 'callback_data_value', - 'switch_inline_query' => 'switch_inline_query_value', - ]); - }, - function () { - new InlineKeyboardButton([ - 'text' => 'message', - 'callback_data' => 'callback_data_value', - 'switch_inline_query_current_chat' => 'switch_inline_query_current_chat_value', - ]); - }, - function () { - new InlineKeyboardButton([ - 'text' => 'message', - 'callback_data' => 'callback_data_value', - 'switch_inline_query_chosen_chat' => new SwitchInlineQueryChosenChat([]), - ]); - }, - function () { - new InlineKeyboardButton([ - 'text' => 'message', - 'callback_data' => 'callback_data_value', - 'callback_game' => new CallbackGame([]), - ]); - }, - function () { - new InlineKeyboardButton([ - 'text' => 'message', - 'callback_data' => 'callback_data_value', - 'pay' => true, - ]); - }, - ]; - - $test_funcs[array_rand($test_funcs)](); - } - public function testInlineKeyboardButtonSuccess(): void { new InlineKeyboardButton(['text' => 'message', 'url' => 'url_value']); diff --git a/tests/Unit/Entities/KeyboardButtonTest.php b/tests/Unit/Entities/KeyboardButtonTest.php index 806b807b..d8fc7840 100644 --- a/tests/Unit/Entities/KeyboardButtonTest.php +++ b/tests/Unit/Entities/KeyboardButtonTest.php @@ -28,20 +28,6 @@ */ class KeyboardButtonTest extends TestCase { - public function testKeyboardButtonNoTextFail(): void - { - $this->expectException(TelegramException::class); - $this->expectExceptionMessage('You must add some text to the button!'); - new KeyboardButton([]); - } - - public function testKeyboardButtonTooManyParametersFail(): void - { - $this->expectException(TelegramException::class); - $this->expectExceptionMessage('You must use only one of these fields: request_user, request_chat, request_contact, request_location, request_poll, web_app!'); - new KeyboardButton(['text' => 'message', 'request_contact' => true, 'request_location' => true]); - } - public function testKeyboardButtonSuccess(): void { new KeyboardButton(['text' => 'message']); From b0bbf77677cf9e19050f2d66de8bcfd284b99f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20L=C3=BCscher?= Date: Sat, 6 May 2023 11:28:20 +0200 Subject: [PATCH 2/3] Fix tests and add PHP 8.2 --- .github/workflows/tests.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index e9970c86..ed96f801 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - php: ['7.3', '7.4', '8.0', '8.1'] + php: ['7.3', '7.4', '8.0', '8.1', '8.2'] services: mariadb: @@ -31,6 +31,12 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - name: Verify MariaDB connection + run: | + while ! mysqladmin ping -h127.0.0.1 -P3306 --silent; do + sleep 1 + done + - name: Test migrations run: | git fetch origin 0.44.1 && git checkout FETCH_HEAD -- structure.sql From eaa40f3058efa5b9d52305072203e68d60d85538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20L=C3=BCscher?= Date: Sat, 6 May 2023 11:47:09 +0200 Subject: [PATCH 3/3] Fix test coverage --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 60ed969d..e05fe704 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "\"vendor/bin/phpunit\"" ], "test-cov": [ - "\"vendor/bin/phpunit\" --coverage-clover clover.xml" + "XDEBUG_MODE=coverage \"vendor/bin/phpunit\" --coverage-clover clover.xml" ], "test-cov-upload": [ "wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover clover.xml"