Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use PHPMD for code validation #8

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
60 changes: 60 additions & 0 deletions .github/workflows/validate-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: PHP validate and Unit Test

on:
push:
pull_request:

concurrency:
group: test

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3

- name: Create Environments
run: echo "${{ secrets.TEST_ENV_VARIABLES }}" > .env

- name: Install and update Composer packages
run: composer run-script install-dependencies

- name: Run test suite
run: composer run-script phpunit-test

validate:
runs-on: ubuntu-latest

steps:
- name: Setup PHP
uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '8.3'

- name: Checkout code
uses: actions/checkout@v3

- name: Validate PHP version
run: php -v

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3

- name: Install and update Composer packages
run: composer install --ignore-platform-reqs

- name: Run PHP mess detector
run: composer run-script mess-detect
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
/example.php
/.telegram-bot
/.phpunit.result.cache

/.phpunit.cache
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ use TelegramBot\Entities\WebAppData;
class MainPlugin extends \TelegramBot\Plugin {

public function onMessage(int $update_id, Message $message): \Generator {
if ($message->getText() === '/start') {
if ($message->getText(false) === '/start') {
yield \TelegramBot\Request::sendMessage([
'chat_id' => $message->getChat()->getId(),
'text' => 'Hello, ' . $message->getFrom()->getFirstName(),
]);
}

if ($message->getText() === '/ping') {
if ($message->getText(false) === '/ping') {
yield \TelegramBot\Request::sendMessage([
'chat_id' => $message->getChat()->getId(),
'text' => 'pong',
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"test": "phpunit --colors=always --configuration phpunit.xml"
"install-dependencies": "composer install --ignore-platform-reqs",
"phpunit-test": "vendor/bin/phpunit --colors=always --configuration phpunit.xml",
"mess-detect": "vendor/bin/phpmd ./src text phpmd.xml"
},
"require": {
"php": ">=8.2",
Expand All @@ -40,6 +42,7 @@
},
"require-dev": {
"fakerphp/faker": "^1.23",
"phpmd/phpmd": "^2.15",
"phpunit/phpunit": "^11.2",
"psr/log": "^1.1|^2.0|^3.0"
},
Expand Down
Loading