diff --git a/.editorconfig b/.editorconfig index 2c9d89d..0163872 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,5 +1,6 @@ -# This file is for unifying the coding style for different editors and IDEs -# editorconfig.org +# This file is for unifying the coding style for different editors and IDEs. +# It is based on https://core.trac.wordpress.org/browser/trunk/.editorconfig. +# See https://editorconfig.org for more information about the standard. # WordPress Coding Standards # https://make.wordpress.org/core/handbook/coding-standards/ @@ -9,16 +10,16 @@ root = true [*] charset = utf-8 end_of_line = lf -indent_size = 4 -tab_width = 4 -indent_style = tab insert_final_newline = true trim_trailing_whitespace = true +indent_style = tab -[*.txt] -trim_trailing_whitespace = false +[*.yml] +indent_style = space +indent_size = 2 -[*.{md,json,yml}] +[*.md] trim_trailing_whitespace = false -indent_style = space -indent_size = 2 \ No newline at end of file + +[*.txt] +end_of_line = crlf diff --git a/.github/workflows/cs-lint.yml b/.github/workflows/cs-lint.yml new file mode 100644 index 0000000..fe4dac4 --- /dev/null +++ b/.github/workflows/cs-lint.yml @@ -0,0 +1,70 @@ +name: CS & Lint + +on: + # Run on all pushes and on all pull requests. + # Prevent the "push" build from running when there are only irrelevant changes. + push: + paths-ignore: + - "**.md" + pull_request: + # Allow manually triggering the workflow. + workflow_dispatch: + +jobs: + checkcs: + name: "Basic CS and QA checks" + runs-on: ubuntu-latest + + env: + XMLLINT_INDENT: " " + + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "7.4" + coverage: none + tools: cs2pr + + # Show PHP lint violations inline in the file diff. + # @link https://github.com/marketplace/actions/xmllint-problem-matcher + - name: Register PHP lint violations to appear as file diff comments + uses: korelstar/phplint-problem-matcher@v1 + + # Show XML violations inline in the file diff. + # @link https://github.com/marketplace/actions/xmllint-problem-matcher + - name: Register XML violations to appear as file diff comments + uses: korelstar/xmllint-problem-matcher@v1 + + - name: Checkout code + uses: actions/checkout@v2 + + # Validate the composer.json file. + # @link https://getcomposer.org/doc/03-cli.md#validate + - name: Validate Composer installation + run: composer validate --no-check-all + + # Install dependencies and handle caching in one go. + # @link https://github.com/marketplace/actions/install-composer-dependencies + - name: Install Composer dependencies + uses: ramsey/composer-install@v1 + + # Lint PHP. + - name: Lint PHP against parse errors + run: composer lint-ci | cs2pr + + # Needed as runs-on: system doesn't have xml-lint by default. + # @link https://github.com/marketplace/actions/xml-lint + - name: Lint phpunit.xml.dist + uses: ChristophWurst/xmllint-action@v1 + with: + xml-file: ./phpunit.xml.dist + xml-schema-file: ./vendor/phpunit/phpunit/phpunit.xsd + + # Check the code-style consistency of the PHP files. +# - name: Check PHP code style +# continue-on-error: true +# run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml + +# - name: Show PHPCS results in PR +# run: cs2pr ./phpcs-report.xml diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml deleted file mode 100644 index 7f90c50..0000000 --- a/.github/workflows/integrate.yml +++ /dev/null @@ -1,71 +0,0 @@ -name: Run PHPUnit and PHPCS - -on: [push] - -jobs: - test: - name: WP ${{ matrix.wordpress }} on PHP ${{ matrix.php }} - # Ubuntu-20.x includes MySQL 8.0, which causes `caching_sha2_password` issues with PHP < 7.4 - # https://www.php.net/manual/en/mysqli.requirements.php - # TODO: change to ubuntu-latest when we no longer support PHP < 7.4 - runs-on: ubuntu-18.04 - continue-on-error: ${{ matrix.allowed_failure }} - - env: - WP_VERSION: ${{ matrix.wordpress }} - - strategy: - fail-fast: false - matrix: - php: ["5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0"] - wordpress: ["5.5", "5.6", "5.7"] - allowed_failure: [false] - # https://make.wordpress.org/core/2020/11/23/wordpress-and-php-8-0/ - exclude: - - php: "8.0" - wordpress: "5.5" - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up PHP ${{ matrix.php }} - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - coverage: pcov - # https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions - extensions: curl, dom, exif, fileinfo, hash, json, mbstring, mysqli, openssl, pcre, imagick, xml, zip - - - name: Install Composer dependencies (PHP < 8.0 ) - if: ${{ matrix.php < 8.0 }} - uses: ramsey/composer-install@v1 - - - name: Install Composer dependencies (PHP >= 8.0) - if: ${{ matrix.php >= 8.0 }} - uses: ramsey/composer-install@v1 - with: - composer-options: --ignore-platform-reqs - - - name: Setup Problem Matchers for PHPUnit - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - - name: Show PHP and PHPUnit version info - run: | - php --version - ./vendor/bin/phpunit --version - - - name: Start MySQL service - run: sudo /etc/init.d/mysql start - - - name: Install WordPress environment - run: composer prepare ${{ matrix.wordpress }} - - - name: Run integration tests (single site) - run: composer integration - - - name: Run integration tests (multisite) - run: composer integration-ms - - - name: Run PHPCS - run: composer cs diff --git a/.github/workflows/integrations.yml b/.github/workflows/integrations.yml new file mode 100644 index 0000000..8f5577e --- /dev/null +++ b/.github/workflows/integrations.yml @@ -0,0 +1,85 @@ +name: Run PHPUnit + +on: + # Run on all pushes and on all pull requests. + # Prevent the "push" build from running when there are only irrelevant changes. + push: + paths-ignore: + - "**.md" + pull_request: + # Allow manually triggering the workflow. + workflow_dispatch: + +jobs: + test: + name: WP ${{ matrix.wordpress }} on PHP ${{ matrix.php }} + # Ubuntu-20.x includes MySQL 8.0, which causes `caching_sha2_password` issues with PHP < 7.4 + # https://www.php.net/manual/en/mysqli.requirements.php + # TODO: change to ubuntu-latest when we no longer support PHP < 7.4 + runs-on: ubuntu-18.04 + + env: + WP_VERSION: ${{ matrix.wordpress }} + + strategy: + matrix: + wordpress: ["5.5", "5.6", "5.7"] + php: ["5.6", "7.0", "7.1", "7.2", "7.3", "7.4"] + include: + - php: "8.0" + # Ignore platform requirements, so that PHPUnit 7.5 can be installed on PHP 8.0 (and above). + composer-options: "--ignore-platform-reqs" + extensions: pcov + ini-values: pcov.directory=., "pcov.exclude=\"~(vendor|tests)~\"" + coverage: pcov + exclude: + - php: "8.0" + wordpress: "5.5" + fail-fast: false + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: ${{ matrix.extensions }} + ini-values: ${{ matrix.ini-values }} + coverage: ${{ matrix.coverage }} + + - name: Setup problem matchers for PHP + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + # Setup PCOV since we're using PHPUnit < 8 which has it integrated. Requires PHP 7.1. + # Ignore platform reqs to make it install on PHP 8. + # https://github.com/krakjoe/pcov-clobber + - name: Setup PCOV + if: ${{ matrix.php == 8.0 }} + run: | + composer require pcov/clobber --ignore-platform-reqs + vendor/bin/pcov clobber + + - name: Setup Problem Matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install Composer dependencies + uses: ramsey/composer-install@v1 + with: + composer-options: "${{ matrix.composer-options }}" + + - name: Start MySQL Service + run: sudo systemctl start mysql.service + + - name: Prepare environment for integration tests + run: composer prepare-ci + + - name: Run integration tests (single site) + if: ${{ matrix.php != 8.0 }} + run: composer test + - name: Run integration tests (single site with code coverage) + if: ${{ matrix.php == 8.0 }} + run: composer coverage-ci + - name: Run integration tests (multisite) + run: composer test-ms diff --git a/.gitignore b/.gitignore index fe80a93..af1f417 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ -.DS_Store -.vscode/ composer.lock -vendor/ +/vendor diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist new file mode 100644 index 0000000..301811c --- /dev/null +++ b/.phpcs.xml.dist @@ -0,0 +1,70 @@ + + + Custom ruleset for syndication plugin. + + + + + + . + + /vendor/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/composer.json b/composer.json index 83ef2cb..65160e7 100644 --- a/composer.json +++ b/composer.json @@ -1,58 +1,64 @@ { - "name": "automattic/syndication", - "description": "Syndication helps users manage posts across multiple sites. It's useful when managing posts on different platforms. With a single click you can push or pull a post to or from more than 100 sites.", - "keywords": [ - "wordpress" - ], - "homepage": "https://github.com/Automattic/syndication/", - "type": "wordpress-plugin", - "license": "GPL-2.0+", - "authors": [ - { - "name": "Automattic", - "homepage": "http://automattic.com/" - } - ], - "support": { - "issues": "https://github.com/Automattic/syndication/issues", - "source": "https://github.com/Automattic/syndication" - }, - "require": { - "composer/installers": "~1.0", - "php": ">=5.6" - }, - "require-dev": { - "automattic/vipwpcs": "^2.2", - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7", - "php-parallel-lint/php-parallel-lint": "^1.0", - "phpcompatibility/phpcompatibility-wp": "^2.1", - "phpunit/phpunit": "^4 || ^5 || ^6 || ^7", - "squizlabs/php_codesniffer": "^3.5", - "wp-coding-standards/wpcs": "^2.3.0", - "yoast/phpunit-polyfills": "^0.2.0" - }, - "scripts": { - "cs": [ - "@php ./vendor/bin/phpcs -p -s -v -n . --standard=\"WordPress-VIP-Go\" --extensions=php --ignore=\"/vendor/*,/node_modules/*,/tests/*\"" - ], - "cbf": [ - "@php ./vendor/bin/phpcbf -p -s -v -n . --standard=\"WordPress-VIP-Go\" --extensions=php --ignore=\"/vendor/*,/node_modules/*,/tests/*\"" - ], - "lint": [ - "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git" - ], - "lint-ci": [ - "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git --checkstyle" - ], - "prepare": [ - "bash bin/install-wp-tests.sh wordpress_test root root localhost" - ], - "integration": [ - "@php ./vendor/bin/phpunit --testsuite WP_Tests" - ], - "integration-ms": [ - "@putenv WP_MULTISITE=1", - "@composer integration" - ] - } + "name": "automattic/syndication", + "type": "wordpress-plugin", + "description": "Syndication helps users manage posts across multiple sites. It's useful when managing posts on different platforms. With a single click you can push or pull a post to or from more than 100 sites.", + "keywords": [ + "wordpress" + ], + "homepage": "https://github.com/Automattic/syndication/", + "license": "GPL-2.0-or-later", + "authors": [ + { + "name": "Automattic", + "homepage": "https://automattic.com/" + } + ], + "require": { + "php": ">=5.6", + "composer/installers": "~1.0" + }, + "require-dev": { + "automattic/vipwpcs": "^2.2", + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7", + "php-parallel-lint/php-parallel-lint": "^1.0", + "phpcompatibility/phpcompatibility-wp": "^2.1", + "phpunit/phpunit": "^4 || ^5 || ^6 || ^7", + "squizlabs/php_codesniffer": "^3.5", + "wp-coding-standards/wpcs": "^2.3.0", + "yoast/phpunit-polyfills": "^0.2.0" + }, + "scripts": { + "cbf": [ + "@php ./vendor/bin/phpcbf" + ], + "coverage": [ + "@php ./vendor/bin/phpunit --coverage-html ./build/coverage-html" + ], + "coverage-ci": [ + "@php ./vendor/bin/phpunit" + ], + "cs": [ + "@php ./vendor/bin/phpcs" + ], + "lint": [ + "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git" + ], + "lint-ci": [ + "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git --checkstyle" + ], + "prepare-ci": [ + "bash bin/install-wp-tests.sh wordpress_test root root localhost" + ], + "test": [ + "@php ./vendor/bin/phpunit --testsuite WP_Tests" + ], + "test-ms": [ + "@putenv WP_MULTISITE=1", + "@composer test" + ] + }, + "support": { + "issues": "https://github.com/Automattic/syndication/issues", + "source": "https://github.com/Automattic/syndication" + } } diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 100% rename from phpunit.xml rename to phpunit.xml.dist diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 57bd6f4..f9ca33c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -18,5 +18,3 @@ function _manually_load_plugin() { require $_tests_dir . '/includes/bootstrap.php'; -require dirname( __FILE__ ) . '/push-syndication-testcase.php'; - diff --git a/tests/push-syndication-testcase.php b/tests/push-syndication-testcase.php deleted file mode 100644 index cb51624..0000000 --- a/tests/push-syndication-testcase.php +++ /dev/null @@ -1,13 +0,0 @@ -_toc = $table_of_contents; - } -}