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

Switch to GH Actions - step 5: unit tests #18209

Merged
merged 4 commits into from Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/workflows/unittest.yml
@@ -0,0 +1,78 @@
name: Unit Test

on:
# Run on pushes to select branches and on all pull requests.
push:
branches:
- master
- trunk
- 'release/**'
- 'hotfix/[0-9]+.[0-9]+*'
- 'feature/**'
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
unit-test:
runs-on: ubuntu-latest

strategy:
matrix:
php_version: ['5.6', '7.0', '7.2', '7.4', '8.0', '8.1']

name: "Unit Test: PHP ${{ matrix.php_version }}"

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

# The prefix-dependencies task makes use of reflection-based PHP code that only works on PHP > 7.2.
- name: Install PHP 7.x for generating the vendor_prefixed directory and dependency injection
uses: shivammathur/setup-php@v2
with:
php-version: 7.2
coverage: none

- name: Install Composer dependencies, generate vendor_prefixed directory and run dependency injection
uses: ramsey/composer-install@v2

# Remove packages which are not PHP cross-version compatible and only used for the prefixing.
# - humbug/php-scoper is only needed to actually do the prefixing, so won't be shipped anyway.
# - league/oauth2-client and its dependencies *are* the packages being prefixed.
- name: Delete dependencies which are not cross-version compatible
run: composer remove --dev --no-scripts humbug/php-scoper league/oauth2-client

- name: Remove vendor directory
run: rm -rf vendor/*

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
coverage: none

- name: "Composer: remove PHPUnit root requirement"
run: composer remove --dev phpunit/phpunit --no-update --no-scripts

# Install dependencies and handle caching in one go.
# - Updates the test utilities (and only those!) to the most appropriate version
# for the PHP version on which the tests will be run.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
# Force a `composer update` run.
dependency-versions: "highest"
# But make it selective.
composer-options: "yoast/wp-test-utils --with-dependencies --no-scripts"

- name: Run unit tests
run: composer test
16 changes: 0 additions & 16 deletions .travis.yml
Expand Up @@ -211,22 +211,6 @@ script:
vendor/bin/phpunit -c phpunit-integration.xml.dist
travis_time_finish && travis_fold end "PHP.integration-tests"
fi
- |
if [[ "$PHPUNIT" == "1" && ${TRAVIS_PHP_VERSION:0:1} != "8" && $TRAVIS_PHP_VERSION != "nightly" ]]; then
# PHP < 8
travis_fold start "PHP.tests" && travis_time_start
vendor/bin/phpunit
travis_time_finish && travis_fold end "PHP.tests"
fi
- |
if [[ "$PHPUNIT" == "1" ]] && [[ ${TRAVIS_PHP_VERSION:0:1} == "8" || $TRAVIS_PHP_VERSION == "nightly" ]]; then
# PHP >= 8
travis_fold start "PHP.tests" && travis_time_start
travis_retry composer require --dev phpunit/phpunit:"^9.0" --update-with-dependencies --ignore-platform-reqs --no-interaction &&
travis_retry composer update yoast/wp-test-utils --with-all-dependencies --ignore-platform-reqs --no-interaction &&
vendor/bin/phpunit
travis_time_finish && travis_fold end "PHP.tests"
fi
- |
if [[ "$COVERAGE" == "1" ]]; then
travis_fold start "PHP.coverage" && travis_time_start
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -3,6 +3,7 @@
[![CS](https://github.com/Yoast/wordpress-seo/actions/workflows/cs.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/cs.yml)
[![Lint](https://github.com/Yoast/wordpress-seo/actions/workflows/lint.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/lint.yml)
[![JS](https://github.com/Yoast/wordpress-seo/actions/workflows/js.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/js.yml)
[![Unit Tests](https://github.com/Yoast/wordpress-seo/actions/workflows/unittest.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/unittest.yml)
[![Build Status](https://api.travis-ci.com/Yoast/wordpress-seo.svg?branch=master)](https://travis-ci.com/Yoast/wordpress-seo)
[![Stable Version](https://poser.pugx.org/yoast/wordpress-seo/v/stable.svg)](https://packagist.org/packages/yoast/wordpress-seo)
[![License](https://poser.pugx.org/yoast/wordpress-seo/license.svg)](https://packagist.org/packages/yoast/wordpress-seo)
Expand Down
Expand Up @@ -47,6 +47,8 @@ public function set_up() {
* Tests that the conditional is met when we are saving for Elementor.
*
* @covers ::is_met
*
* @requires PHP < 8.1
*/
public function test_ajax_elementor_save() {
// We are in an Ajax request.
Expand All @@ -65,6 +67,8 @@ public function test_ajax_elementor_save() {
* Tests that the conditional is not met when we are not on a post, and also not in an Elementor save.
*
* @covers ::is_met
*
* @requires PHP < 8.1
*/
public function test_not_post_not_elementor_save() {
// We are in an Ajax request.
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/helpers/input-helper-test.php
Expand Up @@ -36,6 +36,12 @@ public function set_up() {
* @covers ::filter
*/
public function test_filter() {
// These two expectations should be removed once the underlying issue has been resolved.
if ( \PHP_VERSION_ID >= 80100 ) {
$this->expectDeprecation();
$this->expectDeprecationMessage( 'Constant FILTER_SANITIZE_STRING is deprecated' );
}

$this->assertNull( $this->instance->filter( \INPUT_POST, 'bogus', \FILTER_SANITIZE_STRING ) );
}
}
10 changes: 8 additions & 2 deletions tests/unit/main-test.php
Expand Up @@ -62,12 +62,18 @@ protected function set_up() {
* @covers ::get_container
*/
public function test_surfaces() {
// These two expectations should be removed once the underlying issue has been resolved.
if ( \PHP_VERSION_ID >= 80100 ) {
$this->expectDeprecation();
$this->expectDeprecationMessage( 'Constant FILTER_SANITIZE_STRING is deprecated' );
}

// Deprecated classes call _deprecated_function in the constructor, so stub the function to do nothing.
Monkey\Functions\stubs( [ '_deprecated_function' => '__return_null' ] );

// Some classes call the YoastSEO function in the constructor.
Monkey\Functions\expect( 'YoastSEO' )
->andReturn( $this->instance );
// Deprecated classes call _deprecated_function in the constructor.
Monkey\Functions\expect( '_deprecated_function' );

$container = $this->instance->get_container();

Expand Down