From b555d9d67c5bbf81bfbaf25ef9e3253c8e045153 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 16:43:35 +0100 Subject: [PATCH 01/79] Add a small change to create a PR. --- .github/workflows/unit-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index c1fd9850191da7..661f894cb51d27 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -53,6 +53,7 @@ jobs: unit-php: name: PHP + # Runs PHP related CI jobs runs-on: ubuntu-latest if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} From 6547f785a559e48f9adcdc6482251faf0e3a6272 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 17:08:06 +0100 Subject: [PATCH 02/79] Add multiple php versions. --- .github/workflows/unit-test.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 661f894cb51d27..3b2f5af21b6b47 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -52,10 +52,24 @@ jobs: run: npm run test:unit:date -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache" unit-php: - name: PHP + name: PHP - ${{ matrix.php }} # Runs PHP related CI jobs runs-on: ubuntu-latest if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} + strategy: + matrix: + php: + [ + '5.6', + '7.0', + '7.1', + '7.2', + '7.3', + '7.4', + '8.0', + '8.1', + '8.2', + ] steps: - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 From 4bf84bbea59095538ee09437dabc907abd480ae7 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 17:09:12 +0100 Subject: [PATCH 03/79] Add multiple php versions. --- .github/workflows/unit-test.yml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 3b2f5af21b6b47..dad180737497f0 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -58,18 +58,7 @@ jobs: if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} strategy: matrix: - php: - [ - '5.6', - '7.0', - '7.1', - '7.2', - '7.3', - '7.4', - '8.0', - '8.1', - '8.2', - ] + php: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] steps: - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 From 1285d42983e092d0d8b1273f18e99ca908df2eaf Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 17:24:35 +0100 Subject: [PATCH 04/79] Define phpVersion as environment variable. --- .github/workflows/unit-test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index dad180737497f0..97860f41d717ff 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -60,6 +60,9 @@ jobs: matrix: php: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] + env: + WP_ENV_PHP_VERSION: ${{ matrix.php }} + steps: - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 From cd743820ac838ec743b493f9b36f47ae1dfd862f Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 17:55:57 +0100 Subject: [PATCH 05/79] Add phpunit tags for PHP 8.1 and 8.2. --- packages/env/lib/build-docker-compose-config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/env/lib/build-docker-compose-config.js b/packages/env/lib/build-docker-compose-config.js index ff85ba807f00a9..3ebe67a5eb1d43 100644 --- a/packages/env/lib/build-docker-compose-config.js +++ b/packages/env/lib/build-docker-compose-config.js @@ -183,7 +183,7 @@ module.exports = function buildDockerComposeConfig( config ) { phpunitTag = '7' + phpunitPhpVersion; } else if ( [ '7.2', '7.3', '7.4' ].indexOf( testsPhpVersion ) >= 0 ) { phpunitTag = '8' + phpunitPhpVersion; - } else if ( testsPhpVersion === '8.0' ) { + } else if ( [ '8.0', '8.1', '8.2' ].indexOf( testsPhpVersion ) >= 0 ) { phpunitTag = '9' + phpunitPhpVersion; } const phpunitImage = `wordpressdevelop/phpunit:${ phpunitTag }`; From 20e6d53e068103be3efc50fc361c8116f20a5998 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 17:57:31 +0100 Subject: [PATCH 06/79] Remove hyphen. --- .github/workflows/unit-test.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 97860f41d717ff..0daf8b4d7c6f07 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -52,16 +52,27 @@ jobs: run: npm run test:unit:date -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache" unit-php: - name: PHP - ${{ matrix.php }} + name: PHP ${{ matrix.php }} # Runs PHP related CI jobs runs-on: ubuntu-latest if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} strategy: matrix: - php: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] + php: + [ + '5.6', + '7.0', + '7.1', + '7.2', + '7.3', + '7.4', + '8.0', + '8.1', + '8.2', + ] env: - WP_ENV_PHP_VERSION: ${{ matrix.php }} + WP_ENV_PHP_VERSION: ${{ matrix.php }} steps: - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 From f192e2e047798eb5481d225ee87fd8c326c8d640 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 18:23:36 +0100 Subject: [PATCH 07/79] Nove PHPUnit tests to a separate file. --- .github/workflows/phpunit-tests.yml | 69 +++++++++++++++++++++++++++++ .github/workflows/unit-test.yml | 52 ---------------------- 2 files changed, 69 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/phpunit-tests.yml diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml new file mode 100644 index 00000000000000..0c6c8fd64eb55f --- /dev/null +++ b/.github/workflows/phpunit-tests.yml @@ -0,0 +1,69 @@ +name: PHPUnit Tests + +# Since Unit Tests are required to pass for each PR, +# we cannot disable them for documentation-only changes. +on: + pull_request: + push: + branches: + - trunk + - 'release/**' + - 'wp/**' + +# Cancels all previous workflow runs for pull requests that have not completed. +concurrency: + # The concurrency group contains the workflow name and the branch name for pull requests + # or the commit hash for any other events. + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} + cancel-in-progress: true + +jobs: + unit-php: + name: ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }} + # Runs PHP related CI jobs + runs-on: ubuntu-latest + if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} + strategy: + matrix: + php: + [ + '5.6', + '7.0', + '7.1', + '7.2', + '7.3', + '7.4', + '8.0', + '8.1', + '8.2', + ] + multisite: [false, true] + + env: + WP_ENV_PHP_VERSION: ${{ matrix.php }} + + steps: + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 + + - name: Use desired version of NodeJS + uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1 + with: + node-version-file: '.nvmrc' + cache: npm + + - name: Npm install and build + run: | + npm ci + npm run build + + - name: Install WordPress + run: | + npm run wp-env start + + - name: Running single site unit tests + run: npm run test:unit:php + if: ${{ ! matrix.multisite }} + + - name: Running multisite unit tests + run: npm run test:unit:php:multisite + if: ${{ matrix.multisite }} diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 0daf8b4d7c6f07..3b68bfd57c0360 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -51,58 +51,6 @@ jobs: - name: Running the date tests run: npm run test:unit:date -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache" - unit-php: - name: PHP ${{ matrix.php }} - # Runs PHP related CI jobs - runs-on: ubuntu-latest - if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} - strategy: - matrix: - php: - [ - '5.6', - '7.0', - '7.1', - '7.2', - '7.3', - '7.4', - '8.0', - '8.1', - '8.2', - ] - - env: - WP_ENV_PHP_VERSION: ${{ matrix.php }} - - steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 - - - name: Use desired version of NodeJS - uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1 - with: - node-version-file: '.nvmrc' - cache: npm - - - name: Npm install and build - run: | - npm ci - npm run build - - - name: Install WordPress - run: | - npm run wp-env start - - - name: Running lint check - run: npm run lint:php - - - name: Running single site unit tests - run: npm run test:unit:php - if: ${{ success() || failure() }} - - - name: Running multisite unit tests - run: npm run test:unit:php:multisite - if: ${{ success() || failure() }} - mobile-unit-js: name: Mobile runs-on: ubuntu-latest From 0da70aecb38e89b25597ae58950b2789aa2c9d8a Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 18:37:33 +0100 Subject: [PATCH 08/79] Disable `fail-fast`. --- .github/workflows/phpunit-tests.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 0c6c8fd64eb55f..f19017f47b9864 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -18,12 +18,13 @@ concurrency: cancel-in-progress: true jobs: - unit-php: - name: ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }} - # Runs PHP related CI jobs + test-php: + name: ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }} on ${{ matrix.os }} runs-on: ubuntu-latest + timeout-minutes: 20 if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} strategy: + fail-fast: false matrix: php: [ @@ -37,6 +38,7 @@ jobs: '8.1', '8.2', ] + os: [ubuntu-latest] multisite: [false, true] env: @@ -45,21 +47,29 @@ jobs: steps: - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 - - name: Use desired version of NodeJS + - name: Set up Node.js uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1 with: node-version-file: '.nvmrc' cache: npm + - name: Docker debug information + run: | + docker -v + docker-compose -v + - name: Npm install and build run: | npm ci npm run build - - name: Install WordPress + - name: Start Docker environment run: | npm run wp-env start + - name: Log running Docker containers + run: docker ps -a + - name: Running single site unit tests run: npm run test:unit:php if: ${{ ! matrix.multisite }} From c3bbb6a8dc1b4f7a49581b74d9da2ebf025c55b6 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 19:36:23 +0100 Subject: [PATCH 09/79] Update matrix.os. --- .github/workflows/phpunit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index f19017f47b9864..d6142d5c478eab 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -20,7 +20,7 @@ concurrency: jobs: test-php: name: ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }} on ${{ matrix.os }} - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} timeout-minutes: 20 if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} strategy: From 9b6cd4011b1be0f92b948d96a1253970d23fd3d3 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 19:46:37 +0100 Subject: [PATCH 10/79] Install composer dependencies. --- .github/workflows/phpunit-tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index d6142d5c478eab..8cf068bbaa251a 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -63,6 +63,11 @@ jobs: npm ci npm run build + - name: Install Composer dependencies + uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 + with: + custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") + - name: Start Docker environment run: | npm run wp-env start From 53180a4dbe63a53f45c56384e3380aeb39f96890 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 19:47:38 +0100 Subject: [PATCH 11/79] Revert "Install composer dependencies." This reverts commit e433d838d3c6b1a2e546ac407647377e3273050d. --- .github/workflows/phpunit-tests.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 8cf068bbaa251a..d6142d5c478eab 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -63,11 +63,6 @@ jobs: npm ci npm run build - - name: Install Composer dependencies - uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 - with: - custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") - - name: Start Docker environment run: | npm run wp-env start From b60db3d670d36a89e3744ee41217704ca747ba8b Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 20:04:21 +0100 Subject: [PATCH 12/79] Revert "Revert "Install composer dependencies."" This reverts commit 5e13c24e36aec30b69f3a9ab71d06833bdd4ad4b. --- .github/workflows/phpunit-tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index d6142d5c478eab..8cf068bbaa251a 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -63,6 +63,11 @@ jobs: npm ci npm run build + - name: Install Composer dependencies + uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 + with: + custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") + - name: Start Docker environment run: | npm run wp-env start From 2a687ae461983e61fdaf4b3743d9157d5ef5c795 Mon Sep 17 00:00:00 2001 From: "Aaron D. Campbell" Date: Tue, 13 Dec 2022 20:14:28 +0100 Subject: [PATCH 13/79] Fixing "no phpunit found" error. --- .github/workflows/unit-test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 3b68bfd57c0360..850221b36380d3 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -45,6 +45,9 @@ jobs: npm ci npx lerna run build + - name: Running lint check + run: npm run lint:php + - name: Running the tests run: npm run test:unit -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache" From c161a74b1bb1445d48cac1ac4e592793194636d2 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 20:15:17 +0100 Subject: [PATCH 14/79] Revert "Fixing "no phpunit found" error." This reverts commit ee422158de53dd7525009338013fdfcbd0c6c9c6. --- .github/workflows/unit-test.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 850221b36380d3..3b68bfd57c0360 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -45,9 +45,6 @@ jobs: npm ci npx lerna run build - - name: Running lint check - run: npm run lint:php - - name: Running the tests run: npm run test:unit -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache" From 438199842ab4ba7755a4a837f2ed7eef627750cb Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Dec 2022 20:16:31 +0100 Subject: [PATCH 15/79] Add phpunit tags for PHP 8.1 and 8.2. --- .github/workflows/phpunit-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 8cf068bbaa251a..817673c048c5ee 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -75,6 +75,9 @@ jobs: - name: Log running Docker containers run: docker ps -a + - name: Running lint check + run: npm run lint:php + - name: Running single site unit tests run: npm run test:unit:php if: ${{ ! matrix.multisite }} From f340a41e0824969317ad45092120274d3c533478 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 13:32:54 +0100 Subject: [PATCH 16/79] Debug the phpunitImage. --- packages/env/lib/build-docker-compose-config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/env/lib/build-docker-compose-config.js b/packages/env/lib/build-docker-compose-config.js index 3ebe67a5eb1d43..c2b510846828f3 100644 --- a/packages/env/lib/build-docker-compose-config.js +++ b/packages/env/lib/build-docker-compose-config.js @@ -187,6 +187,7 @@ module.exports = function buildDockerComposeConfig( config ) { phpunitTag = '9' + phpunitPhpVersion; } const phpunitImage = `wordpressdevelop/phpunit:${ phpunitTag }`; + console.log( phpunitImage ); // The www-data user in wordpress:cli has a different UID (82) to the // www-data user in wordpress (33). Ensure we use the wordpress www-data From aa50d13fb4829be2bc7a789abb0d4a2587da06bb Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 15:43:19 +0100 Subject: [PATCH 17/79] Use correct composer version. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d67ea9e69835b3..cfa8666aadb45a 100644 --- a/package.json +++ b/package.json @@ -310,9 +310,9 @@ "test:unit:debug": "wp-scripts --inspect-brk test-unit-js --runInBand --no-cache --verbose --config test/unit/jest.config.js ", "test:unit:profile": "wp-scripts --cpu-prof test-unit-js --runInBand --no-cache --verbose --config test/unit/jest.config.js ", "pretest:unit:php": "wp-env start", - "test:unit:php": "wp-env run tests-wordpress /var/www/html/wp-content/plugins/gutenberg/vendor/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose", + "test:unit:php": "wp-env run tests-wordpress /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose", "pretest:unit:php:multisite": "wp-env start", - "test:unit:php:multisite": "wp-env run tests-wordpress /var/www/html/wp-content/plugins/gutenberg/vendor/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose", + "test:unit:php:multisite": "wp-env run tests-wordpress /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose", "test:unit:update": "npm run test:unit -- --updateSnapshot", "test:unit:watch": "npm run test:unit -- --watch", "wp-env": "wp-env" From c67c5b69fc66ef4d7298e7fd5c9e37cf5c5c0278 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 16:18:23 +0100 Subject: [PATCH 18/79] Fix container name. --- .github/workflows/phpunit-tests.yml | 4 ++-- package.json | 4 ++-- packages/env/lib/build-docker-compose-config.js | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 817673c048c5ee..fcc5d66a10dfd7 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -75,8 +75,8 @@ jobs: - name: Log running Docker containers run: docker ps -a - - name: Running lint check - run: npm run lint:php + - name: Install composer depenencies + run: wp-env run composer "update --no-interaction" - name: Running single site unit tests run: npm run test:unit:php diff --git a/package.json b/package.json index cfa8666aadb45a..eadb897343760a 100644 --- a/package.json +++ b/package.json @@ -310,9 +310,9 @@ "test:unit:debug": "wp-scripts --inspect-brk test-unit-js --runInBand --no-cache --verbose --config test/unit/jest.config.js ", "test:unit:profile": "wp-scripts --cpu-prof test-unit-js --runInBand --no-cache --verbose --config test/unit/jest.config.js ", "pretest:unit:php": "wp-env start", - "test:unit:php": "wp-env run tests-wordpress /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose", + "test:unit:php": "wp-env run composer /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose", "pretest:unit:php:multisite": "wp-env start", - "test:unit:php:multisite": "wp-env run tests-wordpress /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose", + "test:unit:php:multisite": "wp-env run composer /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose", "test:unit:update": "npm run test:unit -- --updateSnapshot", "test:unit:watch": "npm run test:unit -- --watch", "wp-env": "wp-env" diff --git a/packages/env/lib/build-docker-compose-config.js b/packages/env/lib/build-docker-compose-config.js index c2b510846828f3..3ebe67a5eb1d43 100644 --- a/packages/env/lib/build-docker-compose-config.js +++ b/packages/env/lib/build-docker-compose-config.js @@ -187,7 +187,6 @@ module.exports = function buildDockerComposeConfig( config ) { phpunitTag = '9' + phpunitPhpVersion; } const phpunitImage = `wordpressdevelop/phpunit:${ phpunitTag }`; - console.log( phpunitImage ); // The www-data user in wordpress:cli has a different UID (82) to the // www-data user in wordpress (33). Ensure we use the wordpress www-data From 9575fc7cf76754745031420d13e0ac5ec48b4e8d Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 16:33:24 +0100 Subject: [PATCH 19/79] Don't modify package.json. Run tests in phpunit-test.yml instead. --- .github/workflows/phpunit-tests.yml | 6 +++--- package.json | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index fcc5d66a10dfd7..60fb03c010b53a 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -76,12 +76,12 @@ jobs: run: docker ps -a - name: Install composer depenencies - run: wp-env run composer "update --no-interaction" + run: npm run wp-env run composer "update --no-interaction" - name: Running single site unit tests - run: npm run test:unit:php + run: wp-env run composer /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose if: ${{ ! matrix.multisite }} - name: Running multisite unit tests - run: npm run test:unit:php:multisite + run: wp-env run composer /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/multisite.xml.dist --verbose if: ${{ matrix.multisite }} diff --git a/package.json b/package.json index eadb897343760a..d67ea9e69835b3 100644 --- a/package.json +++ b/package.json @@ -310,9 +310,9 @@ "test:unit:debug": "wp-scripts --inspect-brk test-unit-js --runInBand --no-cache --verbose --config test/unit/jest.config.js ", "test:unit:profile": "wp-scripts --cpu-prof test-unit-js --runInBand --no-cache --verbose --config test/unit/jest.config.js ", "pretest:unit:php": "wp-env start", - "test:unit:php": "wp-env run composer /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose", + "test:unit:php": "wp-env run tests-wordpress /var/www/html/wp-content/plugins/gutenberg/vendor/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose", "pretest:unit:php:multisite": "wp-env start", - "test:unit:php:multisite": "wp-env run composer /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose", + "test:unit:php:multisite": "wp-env run tests-wordpress /var/www/html/wp-content/plugins/gutenberg/vendor/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose", "test:unit:update": "npm run test:unit -- --updateSnapshot", "test:unit:watch": "npm run test:unit -- --watch", "wp-env": "wp-env" From 4d6bdd42daf07ddd427c879e4e4222db29c28397 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 16:35:53 +0100 Subject: [PATCH 20/79] Don't install composer dependencies twice. --- .github/workflows/phpunit-tests.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 60fb03c010b53a..d2991ba0dd24ff 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -64,9 +64,7 @@ jobs: npm run build - name: Install Composer dependencies - uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 - with: - custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") + run: npm run wp-env run composer "update --no-interaction" - name: Start Docker environment run: | @@ -75,9 +73,6 @@ jobs: - name: Log running Docker containers run: docker ps -a - - name: Install composer depenencies - run: npm run wp-env run composer "update --no-interaction" - - name: Running single site unit tests run: wp-env run composer /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose if: ${{ ! matrix.multisite }} From 461200f2c98dbd8152c8f00042ad74393cede79e Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 16:53:32 +0100 Subject: [PATCH 21/79] Need to prefix commands with npm run. --- .github/workflows/phpunit-tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index d2991ba0dd24ff..3d5e07cf481534 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -63,20 +63,20 @@ jobs: npm ci npm run build - - name: Install Composer dependencies - run: npm run wp-env run composer "update --no-interaction" - - name: Start Docker environment run: | npm run wp-env start + - name: Install Composer dependencies + run: npm run wp-env run composer "update --no-interaction" + - name: Log running Docker containers run: docker ps -a - name: Running single site unit tests - run: wp-env run composer /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose + run: npm run wp-env run composer /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose if: ${{ ! matrix.multisite }} - name: Running multisite unit tests - run: wp-env run composer /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/multisite.xml.dist --verbose + run: npm run wp-env run composer /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/multisite.xml.dist --verbose if: ${{ matrix.multisite }} From b299003fe5d6194bdbe536707dc61ab96452885c Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 16:58:18 +0100 Subject: [PATCH 22/79] Add double dashes to pass flags to wp-env. --- .github/workflows/phpunit-tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 3d5e07cf481534..cf92d25f6b144d 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -68,15 +68,15 @@ jobs: npm run wp-env start - name: Install Composer dependencies - run: npm run wp-env run composer "update --no-interaction" + run: npm run wp-env run composer update -- --no-interaction - name: Log running Docker containers run: docker ps -a - name: Running single site unit tests - run: npm run wp-env run composer /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose + run: npm run wp-env run composer /usr/local/bin/phpunit -- -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist -- --verbose if: ${{ ! matrix.multisite }} - name: Running multisite unit tests - run: npm run wp-env run composer /usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/multisite.xml.dist --verbose + run: npm run wp-env run composer /usr/local/bin/phpunit -- -c /var/www/html/wp-content/plugins/gutenberg/multisite.xml.dist -- --verbose if: ${{ matrix.multisite }} From d722186c22feec636127a6e8ff44b861c454f098 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 18:29:00 +0100 Subject: [PATCH 23/79] Fix name of the environment. --- .github/workflows/phpunit-tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index cf92d25f6b144d..b3136e1615be2d 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -68,15 +68,15 @@ jobs: npm run wp-env start - name: Install Composer dependencies - run: npm run wp-env run composer update -- --no-interaction + run: npm run wp-env run "composer update --no-interaction" - name: Log running Docker containers run: docker ps -a - name: Running single site unit tests - run: npm run wp-env run composer /usr/local/bin/phpunit -- -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist -- --verbose + run: npm run wp-env run phpunit "/usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose" if: ${{ ! matrix.multisite }} - name: Running multisite unit tests - run: npm run wp-env run composer /usr/local/bin/phpunit -- -c /var/www/html/wp-content/plugins/gutenberg/multisite.xml.dist -- --verbose + run: npm run wp-env run phpunit "/usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/multisite.xml.dist --verbose" if: ${{ matrix.multisite }} From 8c774d0823ba357ae5ce91c85509962a85413901 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 18:57:17 +0100 Subject: [PATCH 24/79] Add additional debug information. --- .github/workflows/phpunit-tests.yml | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index b3136e1615be2d..e29dc3d127c403 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -58,21 +58,40 @@ jobs: docker -v docker-compose -v - - name: Npm install and build + - name: Install npm dependencies run: | npm ci npm run build - - name: Start Docker environment + - name: General debug information run: | - npm run wp-env start + npm --version + node --version + curl --version + git --version + svn --version + composer --version + locale -a - name: Install Composer dependencies - run: npm run wp-env run "composer update --no-interaction" + run: npm run wp-env run composer "install --no-interaction" + + - name: Start Docker environment + run: | + npm run wp-env start - name: Log running Docker containers run: docker ps -a + - name: Docker container debug information + run: | + npm run wp-env run tests-mysql "mysql --version" + npm run wp-env run phpunit "php --version" + npm run wp-env run phpunit "php -m" + npm run wp-env run phpunit "php -i" + npm run wp-env run phpunit "/usr/local/bin/phpunit --version" + npm run wp-env run phpunit "locale -a" + - name: Running single site unit tests run: npm run wp-env run phpunit "/usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose" if: ${{ ! matrix.multisite }} From 4319bac88bc7f31cc3dc6018cf017482738471c8 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 19:14:24 +0100 Subject: [PATCH 25/79] Composer dependencies should be installed after wp-env is intialised. --- .github/workflows/phpunit-tests.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index e29dc3d127c403..806eeeec1e3211 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -73,13 +73,13 @@ jobs: composer --version locale -a - - name: Install Composer dependencies - run: npm run wp-env run composer "install --no-interaction" - - name: Start Docker environment run: | npm run wp-env start + - name: Install Composer dependencies + run: npm run wp-env run composer "install --no-interaction" + - name: Log running Docker containers run: docker ps -a @@ -89,6 +89,7 @@ jobs: npm run wp-env run phpunit "php --version" npm run wp-env run phpunit "php -m" npm run wp-env run phpunit "php -i" + npm run wp-env run composer "install --no-interaction" npm run wp-env run phpunit "/usr/local/bin/phpunit --version" npm run wp-env run phpunit "locale -a" From b245bc620d4b99bc97fe61df01016cec22a75341 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 19:24:52 +0100 Subject: [PATCH 26/79] Fix wrong command. --- .github/workflows/phpunit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 806eeeec1e3211..ce5cc069552312 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -89,7 +89,7 @@ jobs: npm run wp-env run phpunit "php --version" npm run wp-env run phpunit "php -m" npm run wp-env run phpunit "php -i" - npm run wp-env run composer "install --no-interaction" + npm run wp-env run composer "--version" npm run wp-env run phpunit "/usr/local/bin/phpunit --version" npm run wp-env run phpunit "locale -a" From 60572681ae201e43745109bdf3075a4e0ef72a31 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 20:09:57 +0100 Subject: [PATCH 27/79] Since the tests are currently run within the Docker containers where the PHP version varies, the same PHP version needs to be configured for the action runner. --- .github/workflows/phpunit-tests.yml | 32 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index ce5cc069552312..e50709ff009c9e 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -53,16 +53,36 @@ jobs: node-version-file: '.nvmrc' cache: npm - - name: Docker debug information - run: | - docker -v - docker-compose -v + ## + # This allows Composer dependencies to be installed using a single step. + # + # Since the tests are currently run within the Docker containers where the PHP version varies, + # the same PHP version needs to be configured for the action runner machine so that the correct + # dependency versions are installed and cached. + ## + - name: Set up PHP + uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0 + with: + php-version: '${{ matrix.php }}' + coverage: none + + # Since Composer dependencies are installed using `composer update` and no lock file is in version control, + # passing a custom cache suffix ensures that the cache is flushed at least once per week. + - name: Install Composer dependencies + uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 + with: + custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") - name: Install npm dependencies run: | npm ci npm run build + - name: Docker debug information + run: | + docker -v + docker-compose -v + - name: General debug information run: | npm --version @@ -77,9 +97,6 @@ jobs: run: | npm run wp-env start - - name: Install Composer dependencies - run: npm run wp-env run composer "install --no-interaction" - - name: Log running Docker containers run: docker ps -a @@ -89,7 +106,6 @@ jobs: npm run wp-env run phpunit "php --version" npm run wp-env run phpunit "php -m" npm run wp-env run phpunit "php -i" - npm run wp-env run composer "--version" npm run wp-env run phpunit "/usr/local/bin/phpunit --version" npm run wp-env run phpunit "locale -a" From f8173c6b5f3cfcda9589a3f60d4cc78a2c8b1c3d Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 20:46:00 +0100 Subject: [PATCH 28/79] Fix path to the multisite.xml. --- .github/workflows/phpunit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index e50709ff009c9e..db9cf6480a1d13 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -114,5 +114,5 @@ jobs: if: ${{ ! matrix.multisite }} - name: Running multisite unit tests - run: npm run wp-env run phpunit "/usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/multisite.xml.dist --verbose" + run: npm run wp-env run phpunit "/usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose" if: ${{ matrix.multisite }} From 0b8dff9721244691d61a6d20ae5290c11bbf3123 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 22:14:32 +0100 Subject: [PATCH 29/79] Fix the test class to be compatible with PHP < 7.3. --- ...ock-pattern-categories-controller-test.php | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/phpunit/class-wp-rest-block-pattern-categories-controller-test.php b/phpunit/class-wp-rest-block-pattern-categories-controller-test.php index beadbfc75d073a..d334cf439b5036 100644 --- a/phpunit/class-wp-rest-block-pattern-categories-controller-test.php +++ b/phpunit/class-wp-rest-block-pattern-categories-controller-test.php @@ -14,7 +14,7 @@ */ class WP_REST_Block_Pattern_Categories_Controller_Test extends WP_Test_REST_Controller_Testcase { protected static $admin_id; - protected static $orig_registry; + protected static $original_instance_value; public function set_up() { parent::set_up(); @@ -26,11 +26,13 @@ public static function wpSetupBeforeClass( $factory ) { self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) ); // Setup an empty testing instance of `WP_Block_Pattern_Categories_Registry` and save the original. - $reflection = new ReflectionClass( 'WP_Block_Pattern_Categories_Registry' ); - $reflection->getProperty( 'instance' )->setAccessible( true ); - self::$orig_registry = $reflection->getStaticPropertyValue( 'instance' ); - $test_registry = new WP_Block_Pattern_Categories_Registry(); - $reflection->setStaticPropertyValue( 'instance', $test_registry ); + $reflection = new ReflectionClass( 'WP_Block_Pattern_Categories_Registry' ); + $instance_property = $reflection->getProperty( 'instance' ); + $instance_property->setAccessible( true ); + self::$original_instance_value = $instance_property->getValue( null ); + + $test_registry = new WP_Block_Pattern_Categories_Registry(); + $instance_property->setValue( $test_registry ); // Register some categories in the test registry. $test_registry->register( 'test', array( 'label' => 'Test' ) ); @@ -42,8 +44,10 @@ public static function wpTearDownAfterClass() { self::delete_user( self::$admin_id ); // Restore the original registry instance. - $reflection = new ReflectionClass( 'WP_Block_Pattern_Categories_Registry' ); - $reflection->setStaticPropertyValue( 'instance', self::$orig_registry ); + $reflection = new ReflectionClass( 'WP_Block_Pattern_Categories_Registry' ); + $instance_property = $reflection->getProperty( 'instance' ); + $instance_property->setValue( self::$original_instance_value ); + $instance_property->setAccessible( false ); } public function test_register_routes() { @@ -79,21 +83,27 @@ public function test_get_items() { public function test_context_param() { $this->markTestIncomplete(); } + public function test_get_item() { $this->markTestIncomplete(); } + public function test_create_item() { $this->markTestIncomplete(); } + public function test_update_item() { $this->markTestIncomplete(); } + public function test_delete_item() { $this->markTestIncomplete(); } + public function test_prepare_item() { $this->markTestIncomplete(); } + public function test_get_item_schema() { $this->markTestIncomplete(); } From 2fbdcc46c6ce7ecf68d48802de534977fe39f009 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Dec 2022 22:24:35 +0100 Subject: [PATCH 30/79] Fix bug in WP_REST_Block_Pattern_Categories_Controller_Test::wpTearDownAfterClass. --- .../class-wp-rest-block-pattern-categories-controller-test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit/class-wp-rest-block-pattern-categories-controller-test.php b/phpunit/class-wp-rest-block-pattern-categories-controller-test.php index d334cf439b5036..bdbaa819ba3f80 100644 --- a/phpunit/class-wp-rest-block-pattern-categories-controller-test.php +++ b/phpunit/class-wp-rest-block-pattern-categories-controller-test.php @@ -46,6 +46,7 @@ public static function wpTearDownAfterClass() { // Restore the original registry instance. $reflection = new ReflectionClass( 'WP_Block_Pattern_Categories_Registry' ); $instance_property = $reflection->getProperty( 'instance' ); + $instance_property->setAccessible( true ); $instance_property->setValue( self::$original_instance_value ); $instance_property->setAccessible( false ); } From 76fcd3206b5324eb1fcc02e003cf9f2cd258e062 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 09:33:31 +0100 Subject: [PATCH 31/79] Remove incompatible PHP packages. --- .github/workflows/phpunit-tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index db9cf6480a1d13..cbb398eb7a24a3 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -73,6 +73,12 @@ jobs: with: custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") + # Since Composer dependencies are installed using `composer update` and no lock file is in version control, + # passing a custom cache suffix ensures that the cache is flushed at least once per week. + - name: Remove PHP 5.6 and PHP 7.0 incompatible packages + if: ${{ matrix.php < '7.1' }} + run: composer remove spatie/phpunit-watcher + - name: Install npm dependencies run: | npm ci From 82745d8e367f26fb17eb91b573034e1ed797ce87 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 10:00:31 +0100 Subject: [PATCH 32/79] Remove incompatible PHP packages. --- .github/workflows/phpunit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index cbb398eb7a24a3..42d1acab2a99cb 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -77,7 +77,7 @@ jobs: # passing a custom cache suffix ensures that the cache is flushed at least once per week. - name: Remove PHP 5.6 and PHP 7.0 incompatible packages if: ${{ matrix.php < '7.1' }} - run: composer remove spatie/phpunit-watcher + run: composer remove spatie/phpunit-watcher --dev - name: Install npm dependencies run: | From db2044e815523aabed5cd90a771bc61e2b0ac353 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 10:11:03 +0100 Subject: [PATCH 33/79] Update description. --- .github/workflows/phpunit-tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 42d1acab2a99cb..640f8e6a528424 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -73,10 +73,10 @@ jobs: with: custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") - # Since Composer dependencies are installed using `composer update` and no lock file is in version control, - # passing a custom cache suffix ensures that the cache is flushed at least once per week. + # The spatie/phpunit-watcher package is not compatible with PHP 5.6 and 7.0. + # Therefore, it should be removed before running the tests. - name: Remove PHP 5.6 and PHP 7.0 incompatible packages - if: ${{ matrix.php < '7.1' }} + if: ${{ matrix.php < '7.1' }} run: composer remove spatie/phpunit-watcher --dev - name: Install npm dependencies From 460da7ce9b8a969f0e237c36649e6f12fac5ef36 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 12:33:06 +0100 Subject: [PATCH 34/79] Remove incompatible PHP packages. --- .github/workflows/phpunit-tests.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 640f8e6a528424..ced837d7728535 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -77,7 +77,7 @@ jobs: # Therefore, it should be removed before running the tests. - name: Remove PHP 5.6 and PHP 7.0 incompatible packages if: ${{ matrix.php < '7.1' }} - run: composer remove spatie/phpunit-watcher --dev + run: composer remove spatie/phpunit-watcher yoast/phpunit-polyfills --dev - name: Install npm dependencies run: | @@ -100,8 +100,7 @@ jobs: locale -a - name: Start Docker environment - run: | - npm run wp-env start + run: npm run wp-env start - name: Log running Docker containers run: docker ps -a From 1f607b5ef3874e71e1bee733a4a817c5f6e0e9bb Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 14:24:31 +0100 Subject: [PATCH 35/79] Remove incompatible PHP packages. --- .github/workflows/phpunit-tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index ced837d7728535..22d090013b720c 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -66,6 +66,10 @@ jobs: php-version: '${{ matrix.php }}' coverage: none + # This step is needed to ensure that Composer installs the correct versions of packages. + - name: Override PHP version in composer.json + run: composer config platform.php ${{ matrix.os }} + # Since Composer dependencies are installed using `composer update` and no lock file is in version control, # passing a custom cache suffix ensures that the cache is flushed at least once per week. - name: Install Composer dependencies @@ -91,6 +95,7 @@ jobs: - name: General debug information run: | + php --version npm --version node --version curl --version From d90b2fc038e127ea244be2adf938547036b86cbf Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 14:27:06 +0100 Subject: [PATCH 36/79] Fix wrong matrix value. --- .github/workflows/phpunit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 22d090013b720c..2e2dd74b89aa10 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -68,7 +68,7 @@ jobs: # This step is needed to ensure that Composer installs the correct versions of packages. - name: Override PHP version in composer.json - run: composer config platform.php ${{ matrix.os }} + run: composer config platform.php ${{ matrix.php }} # Since Composer dependencies are installed using `composer update` and no lock file is in version control, # passing a custom cache suffix ensures that the cache is flushed at least once per week. From 61a096fca9bbf8de2e8a3ad126dbb9f64645e395 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 14:29:46 +0100 Subject: [PATCH 37/79] Remove incompatible PHP packages. --- .github/workflows/phpunit-tests.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 2e2dd74b89aa10..dd60837dc8bc38 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -70,6 +70,12 @@ jobs: - name: Override PHP version in composer.json run: composer config platform.php ${{ matrix.php }} + # The spatie/phpunit-watcher package is not compatible with PHP 5.6 and 7.0. + # Therefore, it should be removed before running the tests. + - name: Remove PHP 5.6 and PHP 7.0 incompatible packages + if: ${{ matrix.php < '7.1' }} + run: composer remove spatie/phpunit-watcher yoast/phpunit-polyfills --dev + # Since Composer dependencies are installed using `composer update` and no lock file is in version control, # passing a custom cache suffix ensures that the cache is flushed at least once per week. - name: Install Composer dependencies @@ -77,12 +83,6 @@ jobs: with: custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") - # The spatie/phpunit-watcher package is not compatible with PHP 5.6 and 7.0. - # Therefore, it should be removed before running the tests. - - name: Remove PHP 5.6 and PHP 7.0 incompatible packages - if: ${{ matrix.php < '7.1' }} - run: composer remove spatie/phpunit-watcher yoast/phpunit-polyfills --dev - - name: Install npm dependencies run: | npm ci From 8232cd14a73dd5e38b4d36a86c7ad7641c51d553 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 14:34:45 +0100 Subject: [PATCH 38/79] Don't remove polyfills. --- .github/workflows/phpunit-tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index dd60837dc8bc38..35e741dec01c28 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -70,11 +70,11 @@ jobs: - name: Override PHP version in composer.json run: composer config platform.php ${{ matrix.php }} - # The spatie/phpunit-watcher package is not compatible with PHP 5.6 and 7.0. + # The spatie/phpunit-watcher package is not compatible with PHP < 7.3. # Therefore, it should be removed before running the tests. - name: Remove PHP 5.6 and PHP 7.0 incompatible packages - if: ${{ matrix.php < '7.1' }} - run: composer remove spatie/phpunit-watcher yoast/phpunit-polyfills --dev + if: ${{ matrix.php < '7.3' }} + run: composer remove spatie/phpunit-watcher --dev --no-update # Since Composer dependencies are installed using `composer update` and no lock file is in version control, # passing a custom cache suffix ensures that the cache is flushed at least once per week. From 5dfa5209300840db4552babc68f4149bb30df450 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 14:50:24 +0100 Subject: [PATCH 39/79] Don't remove spathie package on PHP 7.2. --- .github/workflows/phpunit-tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 35e741dec01c28..219739169f8caf 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -66,14 +66,14 @@ jobs: php-version: '${{ matrix.php }}' coverage: none - # This step is needed to ensure that Composer installs the correct versions of packages. + # Ensure that Composer installs the correct versions of packages. - name: Override PHP version in composer.json run: composer config platform.php ${{ matrix.php }} - # The spatie/phpunit-watcher package is not compatible with PHP < 7.3. - # Therefore, it should be removed before running the tests. - - name: Remove PHP 5.6 and PHP 7.0 incompatible packages - if: ${{ matrix.php < '7.3' }} + # The spatie/phpunit-watcher package is not compatible with PHP < 7.2. + # It must be removed before running the tests. + - name: Remove incompatible Composer packages + if: ${{ matrix.php < '7.2' }} run: composer remove spatie/phpunit-watcher --dev --no-update # Since Composer dependencies are installed using `composer update` and no lock file is in version control, From bc9af74777fb505d431dafec50f62f5cdd9f142f Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 18:28:39 +0100 Subject: [PATCH 40/79] // strpos() doesn't support negative offset values on PHP prior to version 7.1. --- lib/experimental/html/class-wp-html-tag-processor.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/experimental/html/class-wp-html-tag-processor.php b/lib/experimental/html/class-wp-html-tag-processor.php index 9539f0d626e9d6..766fce829b0570 100644 --- a/lib/experimental/html/class-wp-html-tag-processor.php +++ b/lib/experimental/html/class-wp-html-tag-processor.php @@ -1746,6 +1746,17 @@ public function get_updated_html() { $this->updated_bytes = strlen( $this->updated_html ); // 3. Point this tag processor at the original tag opener and consume it +<<<<<<< HEAD +======= + $this->parsed_bytes = strlen( $updated_html_up_to_current_tag_name_end ) - $this->tag_name_length - 2; + + // This ensures compatibility with older PHP versions. + // strpos() doesn't support negative offset values on PHP prior to version 7.1. + // + if ( 0 > $this->parsed_bytes ) { + $this->parsed_bytes = strlen( $this->updated_html ) - abs( $this->parsed_bytes ); + } +>>>>>>> 2a8585c8e2 (// strpos() doesn't support negative offset values on PHP prior to version 7.1.) /* * When we get here we're at the end of the tag name, and we want to rewind to before it From 185f26a0e000499d8200b830107ee722af2842be Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 21:32:15 +0100 Subject: [PATCH 41/79] Add cliPhpVersion config parameter. --- .../env/lib/build-docker-compose-config.js | 19 ++++++++++++++----- packages/env/lib/config/config.js | 12 ++++++++++++ packages/env/lib/config/parse-config.js | 1 + packages/env/lib/config/validate-config.js | 12 ++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/env/lib/build-docker-compose-config.js b/packages/env/lib/build-docker-compose-config.js index 3ebe67a5eb1d43..8465e7cbcb4996 100644 --- a/packages/env/lib/build-docker-compose-config.js +++ b/packages/env/lib/build-docker-compose-config.js @@ -143,7 +143,7 @@ module.exports = function buildDockerComposeConfig( config ) { const developmentPorts = `\${WP_ENV_PORT:-${ config.env.development.port }}:80`; const testsPorts = `\${WP_ENV_TESTS_PORT:-${ config.env.tests.port }}:80`; - // Set the WordPress, WP-CLI, PHPUnit PHP version if defined. + // Set the WordPress, PHPUnit PHP version if defined. const developmentPhpVersion = config.env.development.phpVersion ? config.env.development.phpVersion : ''; @@ -151,6 +151,14 @@ module.exports = function buildDockerComposeConfig( config ) { ? config.env.tests.phpVersion : ''; + // Set the WP-CLI PHP version if defined. + const developmentCliPhpVersion = config.env.development.cliPhpVersion + ? config.env.development.cliPhpVersion + : ''; + const testsCliPhpVersion = config.env.tests.cliPhpVersion + ? config.env.tests.cliPhpVersion + : ''; + // Set the WordPress images with the PHP version tag. const developmentWpImage = `wordpress${ developmentPhpVersion ? ':php' + developmentPhpVersion : '' @@ -158,16 +166,17 @@ module.exports = function buildDockerComposeConfig( config ) { const testsWpImage = `wordpress${ testsPhpVersion ? ':php' + testsPhpVersion : '' }`; + // Set the WordPress CLI images with the PHP version tag. const developmentWpCliImage = `wordpress:cli${ - ! developmentPhpVersion || developmentPhpVersion.length === 0 + ! developmentCliPhpVersion || developmentCliPhpVersion.length === 0 ? '' - : '-php' + developmentPhpVersion + : '-php' + developmentCliPhpVersion }`; const testsWpCliImage = `wordpress:cli${ - ! testsPhpVersion || testsPhpVersion.length === 0 + ! testsCliPhpVersion || testsCliPhpVersion.length === 0 ? '' - : '-php' + testsPhpVersion + : '-php' + testsCliPhpVersion }`; // Defaults are to use the most recent version of PHPUnit that provides diff --git a/packages/env/lib/config/config.js b/packages/env/lib/config/config.js index ca00aebacf4ba9..52054b9e28e757 100644 --- a/packages/env/lib/config/config.js +++ b/packages/env/lib/config/config.js @@ -40,6 +40,7 @@ const md5 = require( '../md5' ); * @property {Object} config Mapping of wp-config.php constants to their desired values. * @property {Object.} mappings Mapping of WordPress directories to local directories which should be mounted. * @property {string} phpVersion Version of PHP to use in the environments, of the format 0.0. + * @property {string} cliPhpVersion Version of PHP to use in the cli service (defined in the docker-compose.yml file). */ /** @@ -88,6 +89,7 @@ module.exports = async function readConfig( configPath ) { const defaultConfiguration = { core: null, // Indicates that the latest stable version should ultimately be used. phpVersion: null, + cliPhpVersion: null, plugins: [], themes: [], port: 8888, @@ -272,6 +274,16 @@ function withOverrides( config ) { config.env.tests.phpVersion = process.env.WP_ENV_PHP_VERSION || config.env.tests.phpVersion; + // Override CLI PHP version with environment variable. + config.env.development.cliPhpVersion = + process.env.WP_ENV_CLI_PHP_VERSION || + config.env.development.cliPhpVersion || + config.env.development.phpVersion; + config.env.tests.cliPhpVersion = + process.env.WP_ENV_CLI_PHP_VERSION || + config.env.tests.cliPhpVersion || + config.env.tests.phpVersion; + const updateEnvUrl = ( configKey ) => { [ 'development', 'tests' ].forEach( ( envKey ) => { try { diff --git a/packages/env/lib/config/parse-config.js b/packages/env/lib/config/parse-config.js index 9528ac8b3528c1..24a39aaae1d148 100644 --- a/packages/env/lib/config/parse-config.js +++ b/packages/env/lib/config/parse-config.js @@ -37,6 +37,7 @@ module.exports = async function parseConfig( config, options ) { return { port: config.port, phpVersion: config.phpVersion, + cliPhpVersion: config.cliPhpVersion, coreSource: includeTestsPath( await parseCoreSource( config.core, options ), options diff --git a/packages/env/lib/config/validate-config.js b/packages/env/lib/config/validate-config.js index 1ecee11010f118..eb6635c555a023 100644 --- a/packages/env/lib/config/validate-config.js +++ b/packages/env/lib/config/validate-config.js @@ -83,6 +83,18 @@ function validateConfig( config, envLocation ) { ); } + if ( + config.cliPhpVersion && + ! ( + typeof config.cliPhpVersion === 'string' && + config.cliPhpVersion.length === 3 + ) + ) { + throw new ValidationError( + `Invalid .wp-env.json: "${ envPrefix }cliPhpVersion" must be a string of the format "0.0".` + ); + } + return config; } From 118286fd2cc3f8874cd735401b1c3cfd7bd096ed Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 22:19:08 +0100 Subject: [PATCH 42/79] Don't use custom commands to run the tests. --- .github/workflows/phpunit-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 219739169f8caf..3fce8b770ab4a7 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -120,9 +120,9 @@ jobs: npm run wp-env run phpunit "locale -a" - name: Running single site unit tests - run: npm run wp-env run phpunit "/usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose" + run: npm run test:unit:php if: ${{ ! matrix.multisite }} - name: Running multisite unit tests - run: npm run wp-env run phpunit "/usr/local/bin/phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose" + run: npm run test:unit:php:multisite if: ${{ matrix.multisite }} From 7abd2c3a1f9b848f6ef309c7379099a247b06e9a Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 22:27:45 +0100 Subject: [PATCH 43/79] Revert "Add cliPhpVersion config parameter." This reverts commit 1a73cd90908a85711c7cc9e7c567a7dc3528b0fa. --- .../env/lib/build-docker-compose-config.js | 19 +++++-------------- packages/env/lib/config/config.js | 12 ------------ packages/env/lib/config/parse-config.js | 1 - packages/env/lib/config/validate-config.js | 12 ------------ 4 files changed, 5 insertions(+), 39 deletions(-) diff --git a/packages/env/lib/build-docker-compose-config.js b/packages/env/lib/build-docker-compose-config.js index 8465e7cbcb4996..3ebe67a5eb1d43 100644 --- a/packages/env/lib/build-docker-compose-config.js +++ b/packages/env/lib/build-docker-compose-config.js @@ -143,7 +143,7 @@ module.exports = function buildDockerComposeConfig( config ) { const developmentPorts = `\${WP_ENV_PORT:-${ config.env.development.port }}:80`; const testsPorts = `\${WP_ENV_TESTS_PORT:-${ config.env.tests.port }}:80`; - // Set the WordPress, PHPUnit PHP version if defined. + // Set the WordPress, WP-CLI, PHPUnit PHP version if defined. const developmentPhpVersion = config.env.development.phpVersion ? config.env.development.phpVersion : ''; @@ -151,14 +151,6 @@ module.exports = function buildDockerComposeConfig( config ) { ? config.env.tests.phpVersion : ''; - // Set the WP-CLI PHP version if defined. - const developmentCliPhpVersion = config.env.development.cliPhpVersion - ? config.env.development.cliPhpVersion - : ''; - const testsCliPhpVersion = config.env.tests.cliPhpVersion - ? config.env.tests.cliPhpVersion - : ''; - // Set the WordPress images with the PHP version tag. const developmentWpImage = `wordpress${ developmentPhpVersion ? ':php' + developmentPhpVersion : '' @@ -166,17 +158,16 @@ module.exports = function buildDockerComposeConfig( config ) { const testsWpImage = `wordpress${ testsPhpVersion ? ':php' + testsPhpVersion : '' }`; - // Set the WordPress CLI images with the PHP version tag. const developmentWpCliImage = `wordpress:cli${ - ! developmentCliPhpVersion || developmentCliPhpVersion.length === 0 + ! developmentPhpVersion || developmentPhpVersion.length === 0 ? '' - : '-php' + developmentCliPhpVersion + : '-php' + developmentPhpVersion }`; const testsWpCliImage = `wordpress:cli${ - ! testsCliPhpVersion || testsCliPhpVersion.length === 0 + ! testsPhpVersion || testsPhpVersion.length === 0 ? '' - : '-php' + testsCliPhpVersion + : '-php' + testsPhpVersion }`; // Defaults are to use the most recent version of PHPUnit that provides diff --git a/packages/env/lib/config/config.js b/packages/env/lib/config/config.js index 52054b9e28e757..ca00aebacf4ba9 100644 --- a/packages/env/lib/config/config.js +++ b/packages/env/lib/config/config.js @@ -40,7 +40,6 @@ const md5 = require( '../md5' ); * @property {Object} config Mapping of wp-config.php constants to their desired values. * @property {Object.} mappings Mapping of WordPress directories to local directories which should be mounted. * @property {string} phpVersion Version of PHP to use in the environments, of the format 0.0. - * @property {string} cliPhpVersion Version of PHP to use in the cli service (defined in the docker-compose.yml file). */ /** @@ -89,7 +88,6 @@ module.exports = async function readConfig( configPath ) { const defaultConfiguration = { core: null, // Indicates that the latest stable version should ultimately be used. phpVersion: null, - cliPhpVersion: null, plugins: [], themes: [], port: 8888, @@ -274,16 +272,6 @@ function withOverrides( config ) { config.env.tests.phpVersion = process.env.WP_ENV_PHP_VERSION || config.env.tests.phpVersion; - // Override CLI PHP version with environment variable. - config.env.development.cliPhpVersion = - process.env.WP_ENV_CLI_PHP_VERSION || - config.env.development.cliPhpVersion || - config.env.development.phpVersion; - config.env.tests.cliPhpVersion = - process.env.WP_ENV_CLI_PHP_VERSION || - config.env.tests.cliPhpVersion || - config.env.tests.phpVersion; - const updateEnvUrl = ( configKey ) => { [ 'development', 'tests' ].forEach( ( envKey ) => { try { diff --git a/packages/env/lib/config/parse-config.js b/packages/env/lib/config/parse-config.js index 24a39aaae1d148..9528ac8b3528c1 100644 --- a/packages/env/lib/config/parse-config.js +++ b/packages/env/lib/config/parse-config.js @@ -37,7 +37,6 @@ module.exports = async function parseConfig( config, options ) { return { port: config.port, phpVersion: config.phpVersion, - cliPhpVersion: config.cliPhpVersion, coreSource: includeTestsPath( await parseCoreSource( config.core, options ), options diff --git a/packages/env/lib/config/validate-config.js b/packages/env/lib/config/validate-config.js index eb6635c555a023..1ecee11010f118 100644 --- a/packages/env/lib/config/validate-config.js +++ b/packages/env/lib/config/validate-config.js @@ -83,18 +83,6 @@ function validateConfig( config, envLocation ) { ); } - if ( - config.cliPhpVersion && - ! ( - typeof config.cliPhpVersion === 'string' && - config.cliPhpVersion.length === 3 - ) - ) { - throw new ValidationError( - `Invalid .wp-env.json: "${ envPrefix }cliPhpVersion" must be a string of the format "0.0".` - ); - } - return config; } From a6d2aee0f8fe371d82a1617c14c4c9fe38138132 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 23:22:03 +0100 Subject: [PATCH 44/79] Don't use the phpunit docker-compose service. --- .github/workflows/phpunit-tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 3fce8b770ab4a7..96019d326c1e64 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -113,11 +113,11 @@ jobs: - name: Docker container debug information run: | npm run wp-env run tests-mysql "mysql --version" - npm run wp-env run phpunit "php --version" - npm run wp-env run phpunit "php -m" - npm run wp-env run phpunit "php -i" - npm run wp-env run phpunit "/usr/local/bin/phpunit --version" - npm run wp-env run phpunit "locale -a" + npm run wp-env run tests-wordpress "php --version" + npm run wp-env run tests-wordpress "php -m" + npm run wp-env run tests-wordpress "php -i" + npm run wp-env run tests-wordpress "/var/www/html/wp-content/plugins/gutenberg/vendor/bin/phpunit --version" + npm run wp-env run tests-wordpress "locale -a" - name: Running single site unit tests run: npm run test:unit:php From 5890fb6ea6475c25320932f5f2e5735d1de1ee85 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 15 Dec 2022 23:59:06 +0100 Subject: [PATCH 45/79] Fix dynamic properties. PHP 8.2 doesn't support dynamic properties. --- phpunit/block-supports/layout-test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/phpunit/block-supports/layout-test.php b/phpunit/block-supports/layout-test.php index a22d77cf35408e..9a01a371f72de5 100644 --- a/phpunit/block-supports/layout-test.php +++ b/phpunit/block-supports/layout-test.php @@ -7,6 +7,21 @@ */ class WP_Block_Supports_Layout_Test extends WP_UnitTestCase { + /** + * @var string|null + */ + private $theme_root; + + /** + * @var array|null + */ + private $orig_theme_dir; + + /** + * @var array|null + */ + private $queries; + public function set_up() { parent::set_up(); $this->theme_root = realpath( __DIR__ . '/../data/themedir1' ); From be706c60ffa8705ae4b0fd36e5c8e30b2a265fbb Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 16 Dec 2022 00:16:37 +0100 Subject: [PATCH 46/79] Fix dynamic properties. PHP 8.2 doesn't support dynamic properties. --- phpunit/class-wp-theme-json-resolver-test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/phpunit/class-wp-theme-json-resolver-test.php b/phpunit/class-wp-theme-json-resolver-test.php index f872b251a77840..7b46dc3cd0d4a2 100644 --- a/phpunit/class-wp-theme-json-resolver-test.php +++ b/phpunit/class-wp-theme-json-resolver-test.php @@ -43,6 +43,21 @@ class WP_Theme_JSON_Resolver_Gutenberg_Test extends WP_UnitTestCase { */ private static $property_core_orig_value; + /** + * @var string|null + */ + private $theme_root; + + /** + * @var array|null + */ + private $orig_theme_dir; + + /** + * @var array|null + */ + private $queries; + public static function set_up_before_class() { parent::set_up_before_class(); From d44e9fad916986a59f379395f665dfa0dd6c5a2c Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 16 Dec 2022 00:18:49 +0100 Subject: [PATCH 47/79] Fix dynamic properties. PHP 8.2 doesn't support dynamic properties. --- phpunit/wp-theme-json-test.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/phpunit/wp-theme-json-test.php b/phpunit/wp-theme-json-test.php index 0d92d33faf88de..96fd1ec82c5f19 100644 --- a/phpunit/wp-theme-json-test.php +++ b/phpunit/wp-theme-json-test.php @@ -6,6 +6,20 @@ */ class WP_Theme_Json_Test extends WP_UnitTestCase { + /** + * @var string|null + */ + private $theme_root; + + /** + * @var array|null + */ + private $orig_theme_dir; + + /** + * @var array|null + */ + private $queries; public function set_up() { parent::set_up(); From 780e12e8375dcb3c6f7f6af478d7a98eb9c97699 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 16 Dec 2022 20:31:53 +0100 Subject: [PATCH 48/79] Allow /.cache/.gitkeep files. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index aebfcd623ad2f0..2bbc2dfaae81fb 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,9 @@ yarn.lock /composer.lock .cache +!/.cache/ +/.cache/** +!/.cache/.gitkeep .eslintcache *.tsbuildinfo From 1cbe0ee6732bdea30450b47f6557f63bc73da60a Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 16 Dec 2022 21:52:52 +0100 Subject: [PATCH 49/79] Add the .gitkeep file. The .cache directory is needed for CI/build tools. --- .cache/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .cache/.gitkeep diff --git a/.cache/.gitkeep b/.cache/.gitkeep new file mode 100644 index 00000000000000..e69de29bb2d1d6 From f1cb17128fd11d826bb2fa982702c3774dc8b791 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 16 Dec 2022 22:01:16 +0100 Subject: [PATCH 50/79] Add PHP Coding Stadnards. --- .github/workflows/coding-standards.yml | 101 +++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 .github/workflows/coding-standards.yml diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml new file mode 100644 index 00000000000000..1b3981faea204a --- /dev/null +++ b/.github/workflows/coding-standards.yml @@ -0,0 +1,101 @@ +name: PHP Coding Standards + +on: + push: + branches: + - trunk + - 'release/**' + - 'wp/**' + pull_request: + paths: + # Any change to a PHP file should run checks. + - '**.php' + # These files configure Composer. Changes could affect the outcome. + - 'composer.*' + # This file configures PHPCS. Changes could affect the outcome. + - 'phpcs.xml.dist' + # Changes to workflow files should always verify all workflows are successful. + - '.github/workflows/*.yml' + +# Cancels all previous workflow runs for pull requests that have not completed. +concurrency: + # The concurrency group contains the workflow name and the branch name for pull requests + # or the commit hash for any other events. + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} + cancel-in-progress: true + +jobs: + # Runs PHP coding standards checks. + # + # Violations are reported inline with annotations. + # + # Performs the following steps: + # - Checks out the repository. + # - Sets up PHP. + # - Configures caching for PHPCS scans. + # - Installs Composer dependencies. + # - Make Composer packages available globally. + # - Runs PHPCS on the full codebase with warnings suppressed. + # - Generate a report for displaying issues as pull request annotations. + # - Runs PHPCS on the `tests` directory without warnings suppressed. + # - Generate a report for displaying `test` directory issues as pull request annotations. + # - Ensures version-controlled files are not modified or deleted. + phpcs: + name: PHP coding standards + runs-on: ubuntu-latest + timeout-minutes: 20 + if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} + + steps: + - name: Checkout repository + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 + + - name: Set up PHP + uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0 + with: + php-version: '7.4' + coverage: none + tools: cs2pr + + # This date is used to ensure that the PHPCS cache is cleared at least once every week. + # http://man7.org/linux/man-pages/man1/date.1.html + - name: "Get last Monday's date" + id: get-date + run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT + + - name: Cache PHPCS scan cache + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11 + with: + path: | + .cache/phpcs-src.json + .cache/phpcs-tests.json + key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }} + + # Since Composer dependencies are installed using `composer update` and no lock file is in version control, + # passing a custom cache suffix ensures that the cache is flushed at least once per week. + - name: Install Composer dependencies + uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 + with: + custom-cache-suffix: ${{ steps.get-date.outputs.date }} + + - name: Make Composer packages available globally + run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH + + - name: Run PHPCS on all Core files + id: phpcs-core + run: phpcs -n --report-full --cache=./.cache/phpcs-src.json --report-checkstyle=./.cache/phpcs-report.xml + + - name: Show PHPCS results in PR + if: ${{ always() && steps.phpcs-core.outcome == 'failure' }} + run: cs2pr ./.cache/phpcs-report.xml + + - name: Check test suite files for warnings + id: phpcs-tests + run: phpcs tests --report-full --cache=./.cache/phpcs-tests.json --report-checkstyle=./.cache/phpcs-tests-report.xml + + - name: Show test suite scan results in PR + if: ${{ always() && steps.phpcs-tests.outcome == 'failure' }} + run: cs2pr ./.cache/phpcs-tests-report.xml + + - name: Ensure version-controlled files are not modified during the tests + run: git diff --exit-code From 2d5e7f0fbed9fd97cd10cda89e11937fdbb03aa5 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 16 Dec 2022 22:03:06 +0100 Subject: [PATCH 51/79] Fix the if condition. --- .github/workflows/coding-standards.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 1b3981faea204a..3684363c7626e8 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -44,7 +44,7 @@ jobs: name: PHP coding standards runs-on: ubuntu-latest timeout-minutes: 20 - if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} + if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} steps: - name: Checkout repository From 1636e2dc5457efe441add75ab07bee24277d9899 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 16 Dec 2022 22:06:32 +0100 Subject: [PATCH 52/79] Fix path. --- .github/workflows/coding-standards.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 3684363c7626e8..bfd7040b644ceb 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -91,7 +91,7 @@ jobs: - name: Check test suite files for warnings id: phpcs-tests - run: phpcs tests --report-full --cache=./.cache/phpcs-tests.json --report-checkstyle=./.cache/phpcs-tests-report.xml + run: phpcs phpunit --report-full --cache=./.cache/phpcs-tests.json --report-checkstyle=./.cache/phpcs-tests-report.xml - name: Show test suite scan results in PR if: ${{ always() && steps.phpcs-tests.outcome == 'failure' }} From f9dfc91b4a0eb779683153c9bd9ef30f52d6a922 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 20 Dec 2022 13:21:09 +0100 Subject: [PATCH 53/79] Rename Core to Gutenberg. --- .github/workflows/coding-standards.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index bfd7040b644ceb..672c2a4ac6e737 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -81,12 +81,12 @@ jobs: - name: Make Composer packages available globally run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH - - name: Run PHPCS on all Core files - id: phpcs-core + - name: Run PHPCS on all Gutenberg files + id: phpcs-gutenberg run: phpcs -n --report-full --cache=./.cache/phpcs-src.json --report-checkstyle=./.cache/phpcs-report.xml - name: Show PHPCS results in PR - if: ${{ always() && steps.phpcs-core.outcome == 'failure' }} + if: ${{ always() && steps.phpcs-gutenberg.outcome == 'failure' }} run: cs2pr ./.cache/phpcs-report.xml - name: Check test suite files for warnings From 10e5d0fa6b25683153da992f342852cb9912f140 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 20 Dec 2022 13:26:40 +0100 Subject: [PATCH 54/79] Add job's description. --- .github/workflows/phpunit-tests.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 96019d326c1e64..6f483382332245 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -18,6 +18,22 @@ concurrency: cancel-in-progress: true jobs: + # Runs the PHPUnit tests for Gutenberg. + # + # Performs the following steps: + # - Sets environment variables. + # - Checks out the repository. + # - Sets up Node.js. + # - Sets up PHP. + # - Installs Composer dependencies. + # - Installs npm dependencies + # - Logs general debug information about the runner. + # - Logs Docker debug information (about the Docker installation within the runner). + # - Starts the wp-env Docker containers. + # - Logs the running Docker containers. + # - Logs debug information about what's installed within the wp-env Docker containers. + # - Install WordPress and Gutenberg within the Docker container. + # - Run the PHPUnit tests. test-php: name: ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} From 31d5f22c05c6002f23764254175284dd76e0e39c Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 20 Dec 2022 13:43:08 +0100 Subject: [PATCH 55/79] Add a comment to explain why we need the /.cache folder. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 2bbc2dfaae81fb..093f5fa23f39cd 100644 --- a/.gitignore +++ b/.gitignore @@ -16,10 +16,12 @@ yarn.lock /perf-envs /composer.lock +# The /.cache folder is needed for the "PHP Coding Standards" CI job. .cache !/.cache/ /.cache/** !/.cache/.gitkeep + .eslintcache *.tsbuildinfo From 5c92300b4548074ae881252676b7e5435ec935f3 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 20 Dec 2022 13:56:35 +0100 Subject: [PATCH 56/79] Add a comment to explain why we need complicated .gitignore rules. --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 093f5fa23f39cd..d524fea8061f3e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,9 @@ yarn.lock /perf-envs /composer.lock -# The /.cache folder is needed for the "PHP Coding Standards" CI job. +# The /.cache folder is needed for the "PHP Coding Standards" CI job, while other .cache folders must be ignored +# It is not possible to re-include a file if a parent directory of that file is excluded +# So, /.cache and /.cache./.gitkeep must be re-included .cache !/.cache/ /.cache/** From c16e8e5e330b23ce69a24875b0a752d03041edc2 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 20 Dec 2022 13:58:52 +0100 Subject: [PATCH 57/79] Fix grammar. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d524fea8061f3e..291a6b4e14cb8b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ yarn.lock # The /.cache folder is needed for the "PHP Coding Standards" CI job, while other .cache folders must be ignored # It is not possible to re-include a file if a parent directory of that file is excluded -# So, /.cache and /.cache./.gitkeep must be re-included +# So, both /.cache and /.cache./.gitkeep must be re-included .cache !/.cache/ /.cache/** From 9ac907382e7e6a97a4837912d24c1a69d7971c06 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 20 Dec 2022 21:58:14 +0100 Subject: [PATCH 58/79] Revert accidental changes. --- .../html/class-wp-html-tag-processor.php | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/lib/experimental/html/class-wp-html-tag-processor.php b/lib/experimental/html/class-wp-html-tag-processor.php index 766fce829b0570..ceae125192c3b1 100644 --- a/lib/experimental/html/class-wp-html-tag-processor.php +++ b/lib/experimental/html/class-wp-html-tag-processor.php @@ -1544,17 +1544,17 @@ public function set_attribute( $name, $value ) { */ if ( preg_match( '~[' . - // Syntax-like characters. - '"\'>&&updated_bytes = strlen( $this->updated_html ); // 3. Point this tag processor at the original tag opener and consume it -<<<<<<< HEAD -======= - $this->parsed_bytes = strlen( $updated_html_up_to_current_tag_name_end ) - $this->tag_name_length - 2; - - // This ensures compatibility with older PHP versions. - // strpos() doesn't support negative offset values on PHP prior to version 7.1. - // - if ( 0 > $this->parsed_bytes ) { - $this->parsed_bytes = strlen( $this->updated_html ) - abs( $this->parsed_bytes ); - } ->>>>>>> 2a8585c8e2 (// strpos() doesn't support negative offset values on PHP prior to version 7.1.) /* * When we get here we're at the end of the tag name, and we want to rewind to before it From 1b0d068a42539deb069af5bac180ddce305813b9 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 20 Dec 2022 22:23:38 +0100 Subject: [PATCH 59/79] Revert accidental changes. --- .../html/class-wp-html-tag-processor.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/experimental/html/class-wp-html-tag-processor.php b/lib/experimental/html/class-wp-html-tag-processor.php index ceae125192c3b1..9539f0d626e9d6 100644 --- a/lib/experimental/html/class-wp-html-tag-processor.php +++ b/lib/experimental/html/class-wp-html-tag-processor.php @@ -1544,17 +1544,17 @@ public function set_attribute( $name, $value ) { */ if ( preg_match( '~[' . - // Syntax-like characters. - '"\'>&& Date: Thu, 22 Dec 2022 16:52:00 +0100 Subject: [PATCH 60/79] Allow manually triggering the workflows. Props to @jrfnl for suggesting it. --- .github/workflows/coding-standards.yml | 2 ++ .github/workflows/phpunit-tests.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 672c2a4ac6e737..e574aec944af19 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -16,6 +16,8 @@ on: - 'phpcs.xml.dist' # Changes to workflow files should always verify all workflows are successful. - '.github/workflows/*.yml' + # Allow manually triggering the workflow. + workflow_dispatch: # Cancels all previous workflow runs for pull requests that have not completed. concurrency: diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 6f483382332245..03c92ccbe6bb2e 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -9,6 +9,8 @@ on: - trunk - 'release/**' - 'wp/**' + # Allow manually triggering the workflow. + workflow_dispatch: # Cancels all previous workflow runs for pull requests that have not completed. concurrency: From 3c9072814e07e2978a583115ca4e5c2522316ec7 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 22 Dec 2022 18:07:25 +0100 Subject: [PATCH 61/79] Remove description. --- .github/workflows/coding-standards.yml | 15 --------------- .github/workflows/phpunit-tests.yml | 16 ---------------- 2 files changed, 31 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index e574aec944af19..def4abab2e4988 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -27,21 +27,6 @@ concurrency: cancel-in-progress: true jobs: - # Runs PHP coding standards checks. - # - # Violations are reported inline with annotations. - # - # Performs the following steps: - # - Checks out the repository. - # - Sets up PHP. - # - Configures caching for PHPCS scans. - # - Installs Composer dependencies. - # - Make Composer packages available globally. - # - Runs PHPCS on the full codebase with warnings suppressed. - # - Generate a report for displaying issues as pull request annotations. - # - Runs PHPCS on the `tests` directory without warnings suppressed. - # - Generate a report for displaying `test` directory issues as pull request annotations. - # - Ensures version-controlled files are not modified or deleted. phpcs: name: PHP coding standards runs-on: ubuntu-latest diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 03c92ccbe6bb2e..66b0209bf4f8ba 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -20,22 +20,6 @@ concurrency: cancel-in-progress: true jobs: - # Runs the PHPUnit tests for Gutenberg. - # - # Performs the following steps: - # - Sets environment variables. - # - Checks out the repository. - # - Sets up Node.js. - # - Sets up PHP. - # - Installs Composer dependencies. - # - Installs npm dependencies - # - Logs general debug information about the runner. - # - Logs Docker debug information (about the Docker installation within the runner). - # - Starts the wp-env Docker containers. - # - Logs the running Docker containers. - # - Logs debug information about what's installed within the wp-env Docker containers. - # - Install WordPress and Gutenberg within the Docker container. - # - Run the PHPUnit tests. test-php: name: ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} From 220bf639dd35eb2257e38ffb4ae54b8f3659ee6a Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 22 Dec 2022 19:04:37 +0100 Subject: [PATCH 62/79] Let's not limit the job by path. --- .github/workflows/coding-standards.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index def4abab2e4988..16b2a0110fd43b 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -6,16 +6,6 @@ on: - trunk - 'release/**' - 'wp/**' - pull_request: - paths: - # Any change to a PHP file should run checks. - - '**.php' - # These files configure Composer. Changes could affect the outcome. - - 'composer.*' - # This file configures PHPCS. Changes could affect the outcome. - - 'phpcs.xml.dist' - # Changes to workflow files should always verify all workflows are successful. - - '.github/workflows/*.yml' # Allow manually triggering the workflow. workflow_dispatch: From 6f158a7ebe55cd41b6d860588350e084d305a7b5 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 22 Dec 2022 19:30:31 +0100 Subject: [PATCH 63/79] PHP 7.3 and 7.4 should use PHPUnit 9. Props to @jrfnl for finding this bug. --- packages/env/lib/build-docker-compose-config.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/env/lib/build-docker-compose-config.js b/packages/env/lib/build-docker-compose-config.js index 3ebe67a5eb1d43..7b27f85a7f6cfb 100644 --- a/packages/env/lib/build-docker-compose-config.js +++ b/packages/env/lib/build-docker-compose-config.js @@ -181,9 +181,11 @@ module.exports = function buildDockerComposeConfig( config ) { phpunitTag = '6' + phpunitPhpVersion; } else if ( testsPhpVersion === '7.1' ) { phpunitTag = '7' + phpunitPhpVersion; - } else if ( [ '7.2', '7.3', '7.4' ].indexOf( testsPhpVersion ) >= 0 ) { + } else if ( testsPhpVersion === '7.2' ) { phpunitTag = '8' + phpunitPhpVersion; - } else if ( [ '8.0', '8.1', '8.2' ].indexOf( testsPhpVersion ) >= 0 ) { + } else if ( + [ '7.3', '7.4', '8.0', '8.1', '8.2' ].indexOf( testsPhpVersion ) >= 0 + ) { phpunitTag = '9' + phpunitPhpVersion; } const phpunitImage = `wordpressdevelop/phpunit:${ phpunitTag }`; From 76a5d0ea794a4b4b2596ccbf52308f2e42755de4 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 12 Jan 2023 19:55:38 +0100 Subject: [PATCH 64/79] Update the changelog. Props to @jrfnl for identifying an issue with PHP 7.4 and 7.4. # Conflicts: # packages/env/CHANGELOG.md --- packages/env/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/env/CHANGELOG.md b/packages/env/CHANGELOG.md index 8bf26e02df19f9..e8e0c0e1b54071 100644 --- a/packages/env/CHANGELOG.md +++ b/packages/env/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +### Bug fix +- PHP 7.3 and 7.4 must use PHPUnit 9. + +### Enhancement +- It's now possible to run PHPUnit tests on PHP 8.1 and 8.2. + ## 5.9.0 (2023-01-02) ## 5.8.0 (2022-12-14) From c1bf30212c10fce756c587a73231cb894ee95306 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 22 Dec 2022 20:16:10 +0100 Subject: [PATCH 65/79] 1. Fix yaml synthax. 2. Don't put the OS version in the matrix. --- .github/workflows/phpunit-tests.yml | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 66b0209bf4f8ba..9c39431af92fba 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -21,26 +21,23 @@ concurrency: jobs: test-php: - name: ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }} on ${{ matrix.os }} - runs-on: ${{ matrix.os }} + name: ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }} on ubuntu-latest + runs-on: ubuntu-latest timeout-minutes: 20 if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} strategy: fail-fast: false matrix: php: - [ - '5.6', - '7.0', - '7.1', - '7.2', - '7.3', - '7.4', - '8.0', - '8.1', - '8.2', - ] - os: [ubuntu-latest] + - '5.6' + - '7.0' + - '7.1' + - '7.2' + - '7.3' + - '7.4' + - '8.0' + - '8.1' + - '8.2' multisite: [false, true] env: From 9c9176656074156e03f6088a69de48a1dc476e23 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 22 Dec 2022 20:36:39 +0100 Subject: [PATCH 66/79] In most repos, the convention is to have the if: above the run:. Props to @jrfnl. --- .github/workflows/phpunit-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 9c39431af92fba..e26d4714d1a736 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -119,9 +119,9 @@ jobs: npm run wp-env run tests-wordpress "locale -a" - name: Running single site unit tests - run: npm run test:unit:php if: ${{ ! matrix.multisite }} + run: npm run test:unit:php - name: Running multisite unit tests - run: npm run test:unit:php:multisite if: ${{ matrix.multisite }} + run: npm run test:unit:php:multisite From 571f5ee9f9dfdd39af9b2506ba881dcb126e5b80 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 22 Dec 2022 21:25:07 +0100 Subject: [PATCH 67/79] Don't log the PHP version; this information is available in the "Set up PHP" step. --- .github/workflows/phpunit-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index e26d4714d1a736..9db7b66e23f633 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -94,7 +94,6 @@ jobs: - name: General debug information run: | - php --version npm --version node --version curl --version From a4c17e4231f89d9c87244edb48438ec48e59d632 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 22 Dec 2022 21:28:11 +0100 Subject: [PATCH 68/79] Don't log the Composer version; this information is available in the "Set up PHP" step. --- .github/workflows/phpunit-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 9db7b66e23f633..9da6eb450695e5 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -99,7 +99,6 @@ jobs: curl --version git --version svn --version - composer --version locale -a - name: Start Docker environment From 8b7348b22cb621aaae8147d1231bf922e0df6cbb Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 22 Dec 2022 23:15:27 +0100 Subject: [PATCH 69/79] 1. Don't scan the unit tests twice. 2. Move the cache option to the phpcs.xml.dist --- .github/workflows/coding-standards.yml | 6 +----- phpcs.xml.dist | 3 +++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 16b2a0110fd43b..84f5b1af50a9b0 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -60,16 +60,12 @@ jobs: - name: Run PHPCS on all Gutenberg files id: phpcs-gutenberg - run: phpcs -n --report-full --cache=./.cache/phpcs-src.json --report-checkstyle=./.cache/phpcs-report.xml + run: phpcs --report-full --report-checkstyle=./.cache/phpcs-report.xml - name: Show PHPCS results in PR if: ${{ always() && steps.phpcs-gutenberg.outcome == 'failure' }} run: cs2pr ./.cache/phpcs-report.xml - - name: Check test suite files for warnings - id: phpcs-tests - run: phpcs phpunit --report-full --cache=./.cache/phpcs-tests.json --report-checkstyle=./.cache/phpcs-tests-report.xml - - name: Show test suite scan results in PR if: ${{ always() && steps.phpcs-tests.outcome == 'failure' }} run: cs2pr ./.cache/phpcs-tests-report.xml diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 7473a44d819bc3..e48167d470ee8f 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -32,6 +32,9 @@ + + + ./bin ./gutenberg.php ./lib From c46a89891cf0fc8e6bf67c28e630c1e32d7d66e3 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 22 Dec 2022 23:18:01 +0100 Subject: [PATCH 70/79] Fix the cs2pr report location. --- .github/workflows/coding-standards.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 84f5b1af50a9b0..c0a81e819f69c9 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -68,7 +68,7 @@ jobs: - name: Show test suite scan results in PR if: ${{ always() && steps.phpcs-tests.outcome == 'failure' }} - run: cs2pr ./.cache/phpcs-tests-report.xml + run: cs2pr ./.cache/phpcs-report.xml - name: Ensure version-controlled files are not modified during the tests run: git diff --exit-code From 2be51c637be7e2efb961b40657b5ee93c8781da1 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 22 Dec 2022 23:26:14 +0100 Subject: [PATCH 71/79] Update the .gitignore rule description. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 291a6b4e14cb8b..71ffc1c5bbb25a 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ yarn.lock /perf-envs /composer.lock -# The /.cache folder is needed for the "PHP Coding Standards" CI job, while other .cache folders must be ignored +# The /.cache folder is needed for phpcs to cache results between runs, while other .cache folders must be ignored # It is not possible to re-include a file if a parent directory of that file is excluded # So, both /.cache and /.cache./.gitkeep must be re-included .cache From ac99768361160786a4b67665fc57fb861cda82b7 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 4 Jan 2023 13:44:52 +0100 Subject: [PATCH 72/79] Enable fast failing to save Github resources as proposed here: https://github.com/WordPress/gutenberg/pull/46510/files#r1055900997 --- .github/workflows/phpunit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 9da6eb450695e5..b6533852cfc8a6 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -26,7 +26,7 @@ jobs: timeout-minutes: 20 if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} strategy: - fail-fast: false + fail-fast: true matrix: php: - '5.6' From 22bffeb1b798d5888b200cd54ab16b83772dfd1e Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 12 Jan 2023 18:33:31 +0100 Subject: [PATCH 73/79] As the separate PHPCS run for the tests has been removed, this step should be removed as well. Props to @jrfnl. --- .github/workflows/coding-standards.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index c0a81e819f69c9..3f2c536288e8df 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -66,9 +66,5 @@ jobs: if: ${{ always() && steps.phpcs-gutenberg.outcome == 'failure' }} run: cs2pr ./.cache/phpcs-report.xml - - name: Show test suite scan results in PR - if: ${{ always() && steps.phpcs-tests.outcome == 'failure' }} - run: cs2pr ./.cache/phpcs-report.xml - - name: Ensure version-controlled files are not modified during the tests run: git diff --exit-code From 7cfdaae087ad4e2171b19d56d666bd5302d2b908 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 12 Jan 2023 18:38:56 +0100 Subject: [PATCH 74/79] Use the development php.ini file (to make any errors more obvious). Props to @jrfnl. --- .github/workflows/coding-standards.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 3f2c536288e8df..372f31dd802c14 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -31,6 +31,7 @@ jobs: uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0 with: php-version: '7.4' + ini-file: development coverage: none tools: cs2pr From 8546c9cf3a95afa60adbff81fb2f50eb0187cc78 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 12 Jan 2023 18:50:47 +0100 Subject: [PATCH 75/79] Use the development php.ini file (to make any errors more obvious). Props to @jrfnl. --- .github/workflows/phpunit-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index b6533852cfc8a6..8612b2b3ddbf73 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -63,6 +63,7 @@ jobs: uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0 with: php-version: '${{ matrix.php }}' + ini-file: development coverage: none # Ensure that Composer installs the correct versions of packages. From 9d0a477b6922f46cc69f7077ac31544a5e82c8a5 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 12 Jan 2023 18:51:22 +0100 Subject: [PATCH 76/79] Revert "Use the development php.ini file (to make any errors more obvious)." This reverts commit eaef3343f85faa8f50f7465eb70105cac961d0ca. --- .github/workflows/coding-standards.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 372f31dd802c14..3f2c536288e8df 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -31,7 +31,6 @@ jobs: uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0 with: php-version: '7.4' - ini-file: development coverage: none tools: cs2pr From 2a371d8e29653c1e0a9b5a229f679ca608e5452a Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 13 Jan 2023 00:24:34 +0100 Subject: [PATCH 77/79] Move the unit tests to unit-test.yml. This is needed because: 1. unit-php job has to be preserved as it's set as required in the GH settings. 2. unit-php job now depends on the test-php job. --- .github/workflows/coding-standards.yml | 70 ---------- .github/workflows/phpunit-tests.yml | 126 ------------------ .github/workflows/unit-test.yml | 176 +++++++++++++++++++++++++ 3 files changed, 176 insertions(+), 196 deletions(-) delete mode 100644 .github/workflows/coding-standards.yml delete mode 100644 .github/workflows/phpunit-tests.yml diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml deleted file mode 100644 index 3f2c536288e8df..00000000000000 --- a/.github/workflows/coding-standards.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: PHP Coding Standards - -on: - push: - branches: - - trunk - - 'release/**' - - 'wp/**' - # Allow manually triggering the workflow. - workflow_dispatch: - -# Cancels all previous workflow runs for pull requests that have not completed. -concurrency: - # The concurrency group contains the workflow name and the branch name for pull requests - # or the commit hash for any other events. - group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} - cancel-in-progress: true - -jobs: - phpcs: - name: PHP coding standards - runs-on: ubuntu-latest - timeout-minutes: 20 - if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} - - steps: - - name: Checkout repository - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 - - - name: Set up PHP - uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0 - with: - php-version: '7.4' - coverage: none - tools: cs2pr - - # This date is used to ensure that the PHPCS cache is cleared at least once every week. - # http://man7.org/linux/man-pages/man1/date.1.html - - name: "Get last Monday's date" - id: get-date - run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT - - - name: Cache PHPCS scan cache - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11 - with: - path: | - .cache/phpcs-src.json - .cache/phpcs-tests.json - key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }} - - # Since Composer dependencies are installed using `composer update` and no lock file is in version control, - # passing a custom cache suffix ensures that the cache is flushed at least once per week. - - name: Install Composer dependencies - uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 - with: - custom-cache-suffix: ${{ steps.get-date.outputs.date }} - - - name: Make Composer packages available globally - run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH - - - name: Run PHPCS on all Gutenberg files - id: phpcs-gutenberg - run: phpcs --report-full --report-checkstyle=./.cache/phpcs-report.xml - - - name: Show PHPCS results in PR - if: ${{ always() && steps.phpcs-gutenberg.outcome == 'failure' }} - run: cs2pr ./.cache/phpcs-report.xml - - - name: Ensure version-controlled files are not modified during the tests - run: git diff --exit-code diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml deleted file mode 100644 index 8612b2b3ddbf73..00000000000000 --- a/.github/workflows/phpunit-tests.yml +++ /dev/null @@ -1,126 +0,0 @@ -name: PHPUnit Tests - -# Since Unit Tests are required to pass for each PR, -# we cannot disable them for documentation-only changes. -on: - pull_request: - push: - branches: - - trunk - - 'release/**' - - 'wp/**' - # Allow manually triggering the workflow. - workflow_dispatch: - -# Cancels all previous workflow runs for pull requests that have not completed. -concurrency: - # The concurrency group contains the workflow name and the branch name for pull requests - # or the commit hash for any other events. - group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} - cancel-in-progress: true - -jobs: - test-php: - name: ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }} on ubuntu-latest - runs-on: ubuntu-latest - timeout-minutes: 20 - if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} - strategy: - fail-fast: true - matrix: - php: - - '5.6' - - '7.0' - - '7.1' - - '7.2' - - '7.3' - - '7.4' - - '8.0' - - '8.1' - - '8.2' - multisite: [false, true] - - env: - WP_ENV_PHP_VERSION: ${{ matrix.php }} - - steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 - - - name: Set up Node.js - uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1 - with: - node-version-file: '.nvmrc' - cache: npm - - ## - # This allows Composer dependencies to be installed using a single step. - # - # Since the tests are currently run within the Docker containers where the PHP version varies, - # the same PHP version needs to be configured for the action runner machine so that the correct - # dependency versions are installed and cached. - ## - - name: Set up PHP - uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0 - with: - php-version: '${{ matrix.php }}' - ini-file: development - coverage: none - - # Ensure that Composer installs the correct versions of packages. - - name: Override PHP version in composer.json - run: composer config platform.php ${{ matrix.php }} - - # The spatie/phpunit-watcher package is not compatible with PHP < 7.2. - # It must be removed before running the tests. - - name: Remove incompatible Composer packages - if: ${{ matrix.php < '7.2' }} - run: composer remove spatie/phpunit-watcher --dev --no-update - - # Since Composer dependencies are installed using `composer update` and no lock file is in version control, - # passing a custom cache suffix ensures that the cache is flushed at least once per week. - - name: Install Composer dependencies - uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 - with: - custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") - - - name: Install npm dependencies - run: | - npm ci - npm run build - - - name: Docker debug information - run: | - docker -v - docker-compose -v - - - name: General debug information - run: | - npm --version - node --version - curl --version - git --version - svn --version - locale -a - - - name: Start Docker environment - run: npm run wp-env start - - - name: Log running Docker containers - run: docker ps -a - - - name: Docker container debug information - run: | - npm run wp-env run tests-mysql "mysql --version" - npm run wp-env run tests-wordpress "php --version" - npm run wp-env run tests-wordpress "php -m" - npm run wp-env run tests-wordpress "php -i" - npm run wp-env run tests-wordpress "/var/www/html/wp-content/plugins/gutenberg/vendor/bin/phpunit --version" - npm run wp-env run tests-wordpress "locale -a" - - - name: Running single site unit tests - if: ${{ ! matrix.multisite }} - run: npm run test:unit:php - - - name: Running multisite unit tests - if: ${{ matrix.multisite }} - run: npm run test:unit:php:multisite diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 3b68bfd57c0360..9f72b05f9c5eb3 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -9,6 +9,8 @@ on: - trunk - 'release/**' - 'wp/**' + # Allow manually triggering the workflow. + workflow_dispatch: # Cancels all previous workflow runs for pull requests that have not completed. concurrency: @@ -51,6 +53,180 @@ jobs: - name: Running the date tests run: npm run test:unit:date -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache" + test-php: + name: PHP ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }} on ubuntu-latest + runs-on: ubuntu-latest + timeout-minutes: 20 + if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} + strategy: + fail-fast: true + matrix: + php: + - '5.6' + - '7.0' + - '7.1' + - '7.2' + - '7.3' + - '7.4' + - '8.0' + - '8.1' + - '8.2' + multisite: [false, true] + + env: + WP_ENV_PHP_VERSION: ${{ matrix.php }} + + steps: + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 + + - name: Set up Node.js + uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1 + with: + node-version-file: '.nvmrc' + cache: npm + + ## + # This allows Composer dependencies to be installed using a single step. + # + # Since the tests are currently run within the Docker containers where the PHP version varies, + # the same PHP version needs to be configured for the action runner machine so that the correct + # dependency versions are installed and cached. + ## + - name: Set up PHP + uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0 + with: + php-version: '${{ matrix.php }}' + ini-file: development + coverage: none + + # Ensure that Composer installs the correct versions of packages. + - name: Override PHP version in composer.json + run: composer config platform.php ${{ matrix.php }} + + # The spatie/phpunit-watcher package is not compatible with PHP < 7.2. + # It must be removed before running the tests. + - name: Remove incompatible Composer packages + if: ${{ matrix.php < '7.2' }} + run: composer remove spatie/phpunit-watcher --dev --no-update + + # Since Composer dependencies are installed using `composer update` and no lock file is in version control, + # passing a custom cache suffix ensures that the cache is flushed at least once per week. + - name: Install Composer dependencies + uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 + with: + custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") + + - name: Install npm dependencies + run: | + npm ci + npm run build + + - name: Docker debug information + run: | + docker -v + docker-compose -v + + - name: General debug information + run: | + npm --version + node --version + curl --version + git --version + svn --version + locale -a + + - name: Start Docker environment + run: npm run wp-env start + + - name: Log running Docker containers + run: docker ps -a + + - name: Docker container debug information + run: | + npm run wp-env run tests-mysql "mysql --version" + npm run wp-env run tests-wordpress "php --version" + npm run wp-env run tests-wordpress "php -m" + npm run wp-env run tests-wordpress "php -i" + npm run wp-env run tests-wordpress "/var/www/html/wp-content/plugins/gutenberg/vendor/bin/phpunit --version" + npm run wp-env run tests-wordpress "locale -a" + + - name: Running single site unit tests + if: ${{ ! matrix.multisite }} + run: npm run test:unit:php + + - name: Running multisite unit tests + if: ${{ matrix.multisite }} + run: npm run test:unit:php:multisite + + phpcs: + name: PHP coding standards + runs-on: ubuntu-latest + timeout-minutes: 20 + if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} + + steps: + - name: Checkout repository + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 + + - name: Set up PHP + uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0 + with: + php-version: '7.4' + coverage: none + tools: cs2pr + + # This date is used to ensure that the PHPCS cache is cleared at least once every week. + # http://man7.org/linux/man-pages/man1/date.1.html + - name: "Get last Monday's date" + id: get-date + run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT + + - name: Cache PHPCS scan cache + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11 + with: + path: .cache/phpcs.json + key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }} + + # Since Composer dependencies are installed using `composer update` and no lock file is in version control, + # passing a custom cache suffix ensures that the cache is flushed at least once per week. + - name: Install Composer dependencies + uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 + with: + custom-cache-suffix: ${{ steps.get-date.outputs.date }} + + - name: Make Composer packages available globally + run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH + + - name: Run PHPCS on all Gutenberg files + id: phpcs-gutenberg + run: phpcs --report-full --report-checkstyle=./.cache/phpcs-report.xml + + - name: Show PHPCS results in PR + if: ${{ always() && steps.phpcs-gutenberg.outcome == 'failure' }} + run: cs2pr ./.cache/phpcs-report.xml + + - name: Ensure version-controlled files are not modified during the tests + run: git diff --exit-code + + # This job is deprecated but should temporarily be present for compatibility reasons. + unit-php: + name: PHP + runs-on: ubuntu-latest + needs: [test-php, phpcs] + if: ${{ always() }} + steps: + - name: Fail the job if the PHPUnit tests fail + if: ${{ needs.test-php.result != 'success' }} + run: exit 1 + + - name: Fail the job if not conforming to the coding standards + if: ${{ needs.phpcs.result != 'success' }} + run: exit 1 + + - name: Mark the job as passed if all the checks pass + if: ${{ needs.test-php.result == 'success' && needs.phpcs.result == 'success' }} + run: exit 0 + mobile-unit-js: name: Mobile runs-on: ubuntu-latest From 8eb3280a0c8fed699aeb4fc011180497de8045f3 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Mon, 16 Jan 2023 12:16:39 +0100 Subject: [PATCH 78/79] Change the description. --- .github/workflows/unit-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 9f72b05f9c5eb3..cd05fea2d7a345 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -208,7 +208,7 @@ jobs: - name: Ensure version-controlled files are not modified during the tests run: git diff --exit-code - # This job is deprecated but should temporarily be present for compatibility reasons. + # This job is deprecated but be present for compatibility reasons. unit-php: name: PHP runs-on: ubuntu-latest From 017ce1651cbd7b8ca15ccfb48395b1cfbfd3853c Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Mon, 16 Jan 2023 12:43:29 +0100 Subject: [PATCH 79/79] Rename the job. --- .github/workflows/unit-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index cd05fea2d7a345..4a5d1f89bb33e6 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -219,7 +219,7 @@ jobs: if: ${{ needs.test-php.result != 'success' }} run: exit 1 - - name: Fail the job if not conforming to the coding standards + - name: "Fail the job if the code doesn't conform to the coding standards" if: ${{ needs.phpcs.result != 'success' }} run: exit 1