Build/Test Tools: Switch back to running the PHPUnit test suite against the src directory instead of build.

Some PHPUnit tests were concerned with the state of files in the `build` directory. In order to allow the tests to run without requiring a build to be run first, these have been moved into assertions that run after the build step (and therefore cause it to fail if they do not pass), or into QUnit tests as necessary.

Various other PHPUnit tests implictly depend on built JavaScript files being present. These files are now touched during the test setup to avoid PHP warnings if the `build` files are not present.

The `wp-tests-config-sample.php` file and the GitHub Actions configuration have also been changed so `ABSPATH` uses `src` instead of `build`, therefore allowing the PHPUnit tests to be run without a build having to be run first. This means all new local installations of WordPress will use `src` for PHPUnit testing. If you would like to switch your existing installation over then change the location of `ABSPATH` in `wp-tests-config.php` to point to `src` instead of `build`.

Props peterwilsoncc, iandunn, gziolo, desroj, johnbillion

Fixes #51734
See #45863


git-svn-id: https://develop.svn.wordpress.org/trunk@50441 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2021-02-26 14:07:53 +00:00
parent a280d5704b
commit 4ab922d224
18 changed files with 195 additions and 218 deletions
+8 -74
View File
@@ -19,7 +19,6 @@ on:
- cron: '0 0 * * 0'
env:
LOCAL_DIR: build
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: ${{ true }}
COMPOSER_INSTALL: ${{ false }}
# Controls which NPM script to use for running PHPUnit tests. Options ar `php` and `php-composer`.
@@ -27,20 +26,12 @@ env:
LOCAL_PHP_MEMCACHED: ${{ false }}
jobs:
# Sets up WordPress for testing or development use.
# Sets up the workflow for testing.
#
# Performs the following steps:
# - Cancels all previous workflow runs for pull requests that have not completed.
# - Checks out the repository.
# - Logs debug information about the runner container.
# - Installs NodeJS 14.
# - Sets up caching for NPM.
# _ Installs NPM dependencies using install-changed to hash the `package.json` file.
# - Builds WordPress to run from the `build` directory.
# - Creates a ZIP file of compiled WordPress.
# - Uploads ZIP file as an artifact.
setup-wordpress:
name: Setup WordPress
setup-workflow:
name: Setup Workflow
runs-on: ubuntu-latest
if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }}
@@ -51,67 +42,16 @@ jobs:
with:
access_token: ${{ github.token }}
- name: Checkout repository
uses: actions/checkout@v2
- name: Log debug information
run: |
echo "$GITHUB_REF"
echo "$GITHUB_EVENT_NAME"
npm --version
node --version
curl --version
git --version
svn --version
php --version
php -i
locale -a
- name: Install NodeJS
uses: actions/setup-node@v2
with:
node-version: 14
- name: Cache NodeJS modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
- name: Install Dependencies
run: npx install-changed --install-command="npm ci"
- name: Build WordPress
run: npm run build
- name: Create ZIP artifact
uses: thedoctor0/zip-release@0.4.1
with:
filename: built-wp-${{ github.sha }}.zip
exclusions: '*.git* /*node_modules/* packagehash.txt'
- name: Upload build artifact
uses: actions/upload-artifact@v2
with:
name: built-wp-${{ github.sha }}
path: built-wp-${{ github.sha }}.zip
if-no-files-found: error
# Runs the PHPUnit tests for WordPress.
#
# Performs the following steps:
# - Set environment variables.
# - Sets up the environment variables needed for testing with memcached (if desired).
# - Downloads the built WordPress artifact from the previous job.
# - Unzips the artifact.
# - Installs NodeJS 14.
# - Sets up caching for NPM.
# _ Installs NPM dependencies using install-changed to hash the `package.json` file.
# - Installs NPM dependencies
# - Configures caching for Composer.
# _ Installs Composer dependencies (if desired).
# - Installs Composer dependencies (if desired).
# - Logs Docker debug information (about both the Docker installation within the runner).
# - Starts the WordPress Docker container.
# - Starts the memcached server after the Docker network has been created (if desired).
@@ -127,7 +67,6 @@ jobs:
# - todo: Configure Slack notifications for failing tests.
test-php:
name: ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }}${{ matrix.memcached && ' with memcached' || '' }} on ${{ matrix.os }}
needs: setup-wordpress
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
@@ -163,13 +102,8 @@ jobs:
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV
- name: Download the built WordPress artifact
uses: actions/download-artifact@v2
with:
name: built-wp-${{ github.sha }}
- name: Unzip built artifact
run: unzip built-wp-${{ github.sha }}.zip
- name: Checkout repository
uses: actions/checkout@v2
- name: Install NodeJS
uses: actions/setup-node@v2
@@ -230,7 +164,7 @@ jobs:
- name: Start the Memcached server.
if: ${{ matrix.memcached }}
run: |
cp tests/phpunit/includes/object-cache.php build/wp-content/object-cache.php
cp tests/phpunit/includes/object-cache.php src/wp-content/object-cache.php
docker run --name memcached --net $(basename "$PWD")_wpdevnet -d memcached
- name: General debug information
-5
View File
@@ -6,7 +6,6 @@ on:
- cron: '0 0 * * *'
env:
LOCAL_DIR: build
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: ${{ true }}
COMPOSER_INSTALL: ${{ false }}
# Controls which NPM script to use for running PHPUnit tests. Options ar `php` and `php-composer`.
@@ -26,7 +25,6 @@ jobs:
# - Installs NodeJS 14.
# - Sets up caching for NPM.
# _ Installs NPM dependencies using install-changed to hash the `package.json` file.
# - Builds WordPress to run from the `build` directory.
# - Logs Docker debug information (about the Docker installation within the runner).
# - Starts the WordPress Docker container.
# - Logs debug general information.
@@ -85,9 +83,6 @@ jobs:
- name: Install Dependencies
run: npx install-changed --install-command="npm ci"
- name: Build WordPress
run: npm run build
- name: Docker debug information
run: |
docker -v