Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature/improve test environment #411

Merged
merged 23 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6e977c9
Tests: make future-compatible
GaryJones Sep 27, 2021
2882362
CI: Use WP trunk with new test improvements
GaryJones Sep 27, 2021
e10ca64
CI: No need for pcov-clobber with PHPUnit 8.5
GaryJones Sep 27, 2021
f97cc1c
Bootstrap: Remove PHP_Token references
GaryJones Sep 27, 2021
64ba6f3
Add coverage report back in
GaryJones Sep 27, 2021
e9d7124
CI: Add support for PHP 8.1 (allowed failures)
GaryJones Sep 27, 2021
8c58bc4
Tests: split into unit and integration tests
GaryJones Sep 27, 2021
82f31d5
Bootstrap: Move global code into a function
GaryJones Sep 27, 2021
18ae800
CI: Support running unit tests
GaryJones Sep 27, 2021
93c21a5
CI: Run unit tests on PHP 8 as well
GaryJones Sep 27, 2021
06defb6
Tests: Define constants from plugin root file
GaryJones Sep 27, 2021
98d3f9f
Tests: Fix CS
GaryJones Sep 27, 2021
4e9ceba
Tests: Fix namespace
GaryJones Sep 27, 2021
605129d
Replace constants
GaryJones Sep 27, 2021
0892320
Various fixes
GaryJones Sep 27, 2021
76c45d5
Composer: Improve coverage scripts
GaryJones Sep 27, 2021
b9098cc
CI: Add PHP 8.2
GaryJones Sep 27, 2021
14839b3
CI: Fix indentation
GaryJones Sep 27, 2021
a7f0387
CI: Run coverage for integration tests
GaryJones Sep 27, 2021
f7e6945
CI: Always run coverage on multisite installs
GaryJones Sep 27, 2021
2a6b4b5
Re-fix Settings link on plugins page
GaryJones Sep 27, 2021
596e628
Merge branch 'develop' into feature/improve-test-environment
pauarge Sep 28, 2021
af54e43
Tests: Re-add PluginActions test
GaryJones Sep 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,33 @@ jobs:
WP_VERSION: latest

strategy:
# PHP 5.6 uses PHPUnit 5.7.27
# PHP 7.0 uses PHPUnit 6.5.14
# PHP 7.1 uses PHPUnit 7.5.20
# PHP 7.2 uses PHPUnit 8.5.21
# PHP 7.3 uses PHPUnit 9.5.10
# PHP 7.4 uses PHPUnit 9.5.10
# PHP 8.0 uses PHPUnit 9.5.10
# PHP 8.1 uses PHPUnit 9.5.10
# Keys:
# - coverage: Whether to run the tests with code coverage.
# - experimental: Whether the build is "allowed to fail".
matrix:
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
experimental: [false]
include:
# Separate out PHP 8.0 so it can run with code coverage.
- 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'
experimental: false
extensions: pcov
ini-values: pcov.directory=., "pcov.exclude=\"~(vendor|tests)~\""
coverage: pcov
# There is no PHP nightly. Due to https://github.com/sebastianbergmann/phpunit/issues/4575 this is never
# going to succeed as WordPress is hard-coded to only support PHPUnit 7.5, and then fix only appears
# in PHPUnit 8.5.14.
- php: '8.1'
experimental: false
- php: '8.2'
experimental: true
fail-fast: false
continue-on-error: ${{ matrix.experimental }}
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -50,22 +64,18 @@ jobs:
- 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
- name: Install Composer dependencies for PHP < 8.2
if: ${{ matrix.php < 8.2 }}
uses: ramsey/composer-install@v1

- name: Install Composer dependencies for PHP >= 8.2
if: ${{ matrix.php >= 8.2 }}
uses: ramsey/composer-install@v1
with:
composer-options: '${{ matrix.composer-options }}'
composer-options: --ignore-platform-reqs

- name: Start MySQL Service
run: sudo systemctl start mysql.service
Expand All @@ -75,9 +85,7 @@ jobs:

- name: Run integration tests (single site)
if: ${{ matrix.php != 8.0 }}
run: composer test
- name: Run integration tests (single site with code coverage)
run: composer testwp
- name: Run integration tests (multisite site with code coverage)
pauarge marked this conversation as resolved.
Show resolved Hide resolved
if: ${{ matrix.php == 8.0 }}
run: composer coverage-ci
- name: Run integration tests (multisite)
run: composer test-ms
run: composer coveragewp-ci
81 changes: 81 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Unit Tests

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: PHP ${{ matrix.php }}
# ubuntu-20.04 / ubuntu-latest includes MySQL 8, which has issues with older versions of PHP.
# ubuntu-18.04 includes PHP versions 7.1-8.0, but 5.6-7.1 are cached, so setup is about 5 seconds.
# See https://setup-php.com/i/452
runs-on: ubuntu-18.04
pauarge marked this conversation as resolved.
Show resolved Hide resolved

env:
WP_VERSION: latest

strategy:
# PHP 5.6 uses PHPUnit 5.7.27
# PHP 7.0 uses PHPUnit 6.5.14
# PHP 7.1 uses PHPUnit 7.5.20
# PHP 7.2 uses PHPUnit 8.5.21
# PHP 7.3 uses PHPUnit 9.5.10
# PHP 7.4 uses PHPUnit 9.5.10
# PHP 8.0 uses PHPUnit 9.5.10
# PHP 8.1 uses PHPUnit 9.5.10
# Keys:
# - coverage: Whether to run the tests with code coverage.
# - experimental: Whether the build is "allowed to fail".
matrix:
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
experimental: [false]
include:
# Separate out PHP 8.0 so it can run with code coverage.
- php: '8.0'
experimental: false
extensions: pcov
ini-values: pcov.directory=., "pcov.exclude=\"~(vendor|tests)~\""
coverage: pcov
- php: '8.1'
experimental: false
- php: '8.2'
experimental: true
fail-fast: false
continue-on-error: ${{ matrix.experimental }}
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"

- name: Setup Problem Matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install Composer dependencies for PHP < 8.2
if: ${{ matrix.php < 8.2 }}
uses: ramsey/composer-install@v1

- name: Install Composer dependencies for PHP >= 8.2
if: ${{ matrix.php >= 8.2 }}
uses: ramsey/composer-install@v1
with:
composer-options: --ignore-platform-reqs

- name: Run unit tests
run: composer test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/build/*.map
.DS_Store
.idea
.phpunit.result.cache
node_modules
/build/logs/
/build/coverage-html/
Expand Down
33 changes: 28 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@
"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/wp-test-utils": "0.2.2"
"yoast/wp-test-utils": "^1"
},
"autoload": {
"classmap": [
"src/"
],
"files": [
"wp-parsely.php"
]
},
"autoload-dev": {
"psr-4": {
Expand All @@ -33,10 +40,19 @@
"scripts": {
"coverage": [
"@putenv WP_MULTISITE=1",
"@php ./vendor/bin/phpunit --coverage-html ./build/coverage-html"
"@php ./vendor/bin/phpunit --coverage-html ./build/coverage-html/unit -v"
],
"coveragewp": [
pauarge marked this conversation as resolved.
Show resolved Hide resolved
"@putenv WP_MULTISITE=1",
"@php ./vendor/bin/phpunit --coverage-html ./build/coverage-html/integration -c phpunit-integration.xml.dist -v"
],
"coverage-ci": [
"@php ./vendor/bin/phpunit"
"@putenv WP_MULTISITE=1",
"@php ./vendor/bin/phpunit -v"
],
"coveragewp-ci": [
pauarge marked this conversation as resolved.
Show resolved Hide resolved
"@putenv WP_MULTISITE=1",
"@php ./vendor/bin/phpunit -c phpunit-integration.xml.dist -v"
],
"cs": [
"@php ./vendor/bin/phpcs"
Expand All @@ -48,14 +64,21 @@
"@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 latest"
"bash bin/install-wp-tests.sh wordpress_test root root localhost trunk"
],
"test": [
"@php ./vendor/bin/phpunit --no-coverage"
],
"test-ms": [
"@putenv WP_MULTISITE=1",
"@composer test"
],
"testwp": [
pauarge marked this conversation as resolved.
Show resolved Hide resolved
"@php ./vendor/bin/phpunit --no-coverage -c phpunit-integration.xml.dist"
],
"testwp-ms": [
pauarge marked this conversation as resolved.
Show resolved Hide resolved
"@putenv WP_MULTISITE=1",
"@composer testwp"
]
},
"scripts-descriptions": {
Expand Down
33 changes: 33 additions & 0 deletions phpunit-integration.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="./tests/Integration/bootstrap.php"
backupGlobals="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
convertDeprecationsToExceptions="true"
forceCoversAnnotation="true"
testdox="true"
>
<php>
<server name="SERVER_PORT" value="80"/>
<server name="HTTP_HOST" value="localhost"/>
<server name="REMOTE_ADDR" value="127.0.0.1"/>
</php>
<testsuites>
<testsuite name="integration">
<directory>./tests/Integration</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">src</directory>
<file>wp-parsely.php</file>
</include>
<report>
<text outputFile="php://stdout"/>
</report>
</coverage>
</phpunit>
26 changes: 13 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
bootstrap="./tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="./tests/Unit/bootstrap.php"
backupGlobals="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
convertDeprecationsToExceptions="true"
forceCoversAnnotation="true"
testdox="true"
>
<php>
<server name="SERVER_PORT" value="80"/>
<server name="HTTP_HOST" value="localhost"/>
<server name="REMOTE_ADDR" value="127.0.0.1"/>
</php>
<testsuites>
<testsuite name="WP_Tests">
<directory>./tests/</directory>
<testsuite name="unit">
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory suffix=".php">src</directory>
<file>wp-parsely.php</file>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</include>
<report>
<text outputFile="php://stdout"/>
</report>
</coverage>
</phpunit>
6 changes: 3 additions & 3 deletions src/Integrations/class-facebook-instant-articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public function integrate() {
* @return void
*/
public function insert_parsely_tracking( &$registry ) {
$options = get_option( \Parsely::OPTIONS_KEY );
if ( ! ( $options['apikey'] ) ) {
$parsely = new \Parsely();
if ( $parsely->api_key_is_missing() ) {
return;
}

$registry[ self::REGISTRY_IDENTIFIER ] = array(
'name' => self::REGISTRY_DISPLAY_NAME,
'payload' => $this->get_embed_code( $options['apikey'] ),
'payload' => $this->get_embed_code( $parsely->get_api_key() ),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/UI/class-plugins-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Plugins_Actions {
* Register action and filter hook callbacks.
*/
public function run() {
add_filter( 'plugin_action_links_' . PARSELY_PLUGIN_BASENAME, array( $this, 'add_plugin_meta_links' ) );
add_filter( 'plugin_action_links_' . plugin_basename( PARSELY_FILE ), array( $this, 'add_plugin_meta_links' ) );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/class-parsely-recommended-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function widget( $args, $instance ) {
$instance['return_limit']
);

$reco_widget_script_asset = require PARSELY_PLUGIN_DIR . 'build/admin-page.asset.php';
$reco_widget_script_asset = require plugin_dir_path( PARSELY_FILE ) . 'build/admin-page.asset.php';

?>

Expand All @@ -131,7 +131,7 @@ public function widget( $args, $instance ) {

wp_register_script(
'wp-parsely-recommended-widget',
PARSELY_PLUGIN_URL . 'build/recommended-widget.js',
plugin_dir_url( PARSELY_FILE ) . 'build/recommended-widget.js',
$reco_widget_script_asset['dependencies'],
PARSELY::get_asset_cache_buster(),
true
Expand Down
Loading