Skip to content

Commit

Permalink
Merge pull request #1395 from php-telegram-bot/1344-remove-keyboard-v…
Browse files Browse the repository at this point in the history
…alidations

Remove keyboard validations
  • Loading branch information
noplanman committed May 7, 2023
2 parents 1c6380a + eaa40f3 commit de24a76
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 140 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 0 additions & 28 deletions src/Entities/InlineKeyboardButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
23 changes: 0 additions & 23 deletions src/Entities/KeyboardButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
73 changes: 0 additions & 73 deletions tests/Unit/Entities/InlineKeyboardButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
14 changes: 0 additions & 14 deletions tests/Unit/Entities/KeyboardButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit de24a76

Please sign in to comment.