From fefbd82c596f3542ffdd0eb80092233c6acc55c4 Mon Sep 17 00:00:00 2001 From: Namoshek Date: Tue, 5 Jan 2021 20:25:53 +0100 Subject: [PATCH] Add code style enforcement and GitHub Actions workflow for tests (#3) * Add PHP_CodeSniffer and fix code style * Add test pipeline and SonarQube analysis * Fix job name of workflow --- .github/workflows/tests.yml | 61 +++++++++++++++++++++++++ .phpcs.xml | 88 +++++++++++++++++++++++++++++++++++++ composer.json | 10 +++++ sonar-project.properties | 18 ++++++++ src/Facades/MQTT.php | 2 +- 5 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/tests.yml create mode 100644 .phpcs.xml create mode 100644 sonar-project.properties diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..407c488 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,61 @@ +name: Tests + +on: + push: + branches: + - master + pull_request: + types: [opened, synchronize, reopened] + +jobs: + test-all: + name: Test PHP ${{ matrix.php-version }} + + runs-on: ubuntu-latest + + strategy: + matrix: + php-version: ['7.4', '8.0'] + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: phpunit:9.5.0 + coverage: pcov + + - name: Setup problem matchers for PHP + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache Composer dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install composer dependencies + run: composer install --prefer-dist --ignore-platform-reqs + + - name: Run tests + run: composer test + + - name: Run SonarQube analysis + uses: sonarsource/sonarcloud-github-action@master + if: matrix.php-version == '8.0' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 0000000..13a360d --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,88 @@ + + + php-mqtt Code Style Standard + + + + + + + + + + + + + + + + + + + + + + src/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + src/* + + + + src + + + + + diff --git a/composer.json b/composer.json index 7f1ea9f..3a65dfe 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,9 @@ "illuminate/support": "~7.0|~8.0", "php-mqtt/client": "v1.0.0-rc1" }, + "require-dev": { + "squizlabs/php_codesniffer": "^3.5" + }, "autoload": { "psr-4": { "PhpMqtt\\Client\\": "src" @@ -38,5 +41,12 @@ "MQTT": "PhpMqtt\\Client\\Facades\\MQTT" } } + }, + "scripts": { + "fix:cs": "vendor/bin/phpcbf", + "test": [ + "@test:cs" + ], + "test:cs": "vendor/bin/phpcs" } } diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..a0ed972 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,18 @@ +sonar.organization=php-mqtt +sonar.projectKey=php-mqtt_laravel-client + +# Paths are relative to the sonar-project.properties file. +sonar.sources=src +#sonar.tests=tests + +# Test report and code coverage related settings. +#sonar.php.tests.reportPath=phpunit.report-junit.xml +#sonar.php.coverage.reportPaths=phpunit.coverage-clover.xml + +# Encoding of the source code. Default is default system encoding. +sonar.sourceEncoding=UTF-8 + +# Links for sonarcloud.io page. +sonar.links.ci=https://github.com/php-mqtt/laravel-client/actions +sonar.links.scm=https://github.com/php-mqtt/laravel-client +sonar.links.issue=https://github.com/php-mqtt/laravel-client/issues diff --git a/src/Facades/MQTT.php b/src/Facades/MQTT.php index 0801cf3..6d0a3a9 100644 --- a/src/Facades/MQTT.php +++ b/src/Facades/MQTT.php @@ -13,8 +13,8 @@ * @method static void disconnect(string $connection = null) * @method static void publish(string $topic, string $message, bool $retain = false, string $connection = null) * - * @see ConnectionManager * @package PhpMqtt\Client\Facades + * @see ConnectionManager */ class MQTT extends Facade {