Skip to content

Commit

Permalink
New. Code. Auto tests implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
Glomberg committed Sep 20, 2024
1 parent 426b5d7 commit 58ec8af
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 1 deletion.
23 changes: 23 additions & 0 deletions .github/workflows/releaseNotice.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Notice about releases via Telegram

on:
release:
types: [published]

jobs:

build:
runs-on: ubuntu-latest
steps:
- name: send telegram message on release
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
${{ github.event.repository.description }} <strong>v${{github.event.release.name}}</strong> released
${{github.event.release.html_url}}
${{ github.event.release.body }}
format: html
disable_web_page_preview: true
27 changes: 27 additions & 0 deletions .github/workflows/reviewNotice.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Notice about review approved via Telegram

on:
pull_request_review:
types: [ submitted ]

jobs:

build:
if: github.event.review.state == 'approved' && toJSON(github.event.pull_request.requested_reviewers) == '[]'
runs-on: ubuntu-latest
steps:
- name: Convert date format
id: date
run: echo "::set-output name=date::$(date -d "${{ github.event.pull_request.created_at }}" +"%Y-%m-%d")"
- name: Send telegram message on review approved
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_PLUGINS_TO }}
token: ${{ secrets.TELEGRAM_REVIEWER_TOKEN }}
message: |
💥🎉🎉🎉💥 Pull-request <a href="${{ github.event.pull_request.html_url }}"><strong>${{ github.event.pull_request.title }}</strong></a>
submitted by <strong>${{ github.event.pull_request.user.login }}</strong> at <strong>${{ steps.date.outputs.date }}</strong>
was <strong>approved</strong> and is ready to merge <a href="${{ github.event.pull_request.html_url }}">➡️</a> !!!
format: html
disable_web_page_preview: true
53 changes: 53 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: PHPUnit, PHPCS, Psalm

on: # event list
push: # on push to each of these branches
branches:
- dev
- fix
- master
pull_request:
branches:
- dev
- master

env: # environment variables (available in any part of the action)
PHP_VERSION: 7.4

jobs:
build:
name: PHPUnit, PHPCS, Psalm
runs-on: ubuntu-latest
env:
DB_CONNECTION: mysql
DB_HOST: localhost
DB_PORT: 3306
DB_DATABASE: wordpress_test
DB_USERNAME: root
DB_PASSWORD: root

steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}

- name: Run MySQL server
run: sudo systemctl start mysql

- name: Code Checkout
uses: actions/checkout@v4

- name: Make the script files executable
run: chmod +x ./tests/wp-test-setup.sh

- name: Install WP develop
run: ./tests/wp-test-setup.sh wordpress_test root root localhost latest

- name: Install Dependencies
run: composer i

- name: Running tests
env:
CLEANTALK_TEST_API_KEY: ${{ secrets.CLEANTALK_TEST_API_KEY }}
run: composer test
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
*
!README.md
!Antispam/
!Antispam/*
!Antispam/*
!.github/
!.github/*
!.github/workflows/
!.github/workflows/*
!composer.json
!tests/
!tests/**
22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"require-dev": {
"vimeo/psalm": "^4.8",
"phpunit/phpunit": "^7.5",
"squizlabs/php_codesniffer": "3.*",
"phpcompatibility/php-compatibility": "@dev"
},
"scripts": {
"test": [
"vendor/bin/phpunit --configuration tests/phpunit.xml",
"vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility",
"vendor/bin/phpcs --standard=tests/.phpcs.xml",
"vendor/bin/psalm --no-cache --config=tests/psalm.xml",
"vendor/bin/psalm --no-cache --config=tests/psalm.xml --taint-analysis"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
27 changes: 27 additions & 0 deletions tests/.phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<ruleset>
<description>Sniff code to check different PHP compatibility</description>

<!-- What to scan -->
<file>../Antispam</file>

<!-- How to scan -->
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<arg value="sp"/> <!-- Show sniff and progress -->
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="exclude" value="PSR12.ControlStructures.ControlStructureSpacing"/>
<arg value="n"/>

<!-- Rules: Check PHP version compatibility -->
<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="5.6-"/>

<rule ref="PHPCompatibility">
<exclude name="PHPCompatibility.ParameterValues.NewHTMLEntitiesFlagsDefault.NotSet"/>
<exclude name="PHPCompatibility.Attributes.NewAttributes.Found"/>
</rule>
<rule ref="PSR12"/>
</ruleset>
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
17 changes: 17 additions & 0 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit
bootstrap="bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="true"
beStrictAboutOutputDuringTests="true"
>
<testsuites>
<testsuite name="CleanTalk Unit Tests">
<directory suffix=".php">./</directory>
<exclude>./bootstrap.php</exclude>
</testsuite>
</testsuites>
</phpunit>
22 changes: 22 additions & 0 deletions tests/psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<psalm
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
name="Psalm for CleanTalk for MediaWiki"
autoloader="bootstrap.php"
errorLevel="3"
throwExceptionOnError="0"
findUnusedCode="true"
ensureArrayStringOffsetsExist="true"
ensureArrayIntOffsetsExist="true"
allowNamedArgumentCalls="false"
hoistConstants="true"
phpVersion="5.6"
hideExternalErrors="true"
xsi:schemaLocation="https://getpsalm.org/schema/config config.xsd"
limitMethodComplexity="true"
>
<projectFiles>
<directory name="../Antispam"/>
</projectFiles>
</psalm>

0 comments on commit 58ec8af

Please sign in to comment.