Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/block-regression.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Block Regression

# Gutenberg ブロックの JS レーン回帰テスト。
# phpunit.yml(PHP unit/integration)ではカバーされない、ブロックの
# JavaScript 側(block.json + edit/save のパース・シリアライズ健全性)を
# WordPress コア流の fixture ラウンドトリップで検証する。

on:
push:
branches: [ master, main, develop ]
pull_request:
branches: [ master, main, develop ]

jobs:
js-fixtures:
name: Block JS fixtures (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: ['22']
defaults:
run:
working-directory: blocks
steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: blocks/package-lock.json

- name: Install dependencies
run: npm ci

- name: Run block fixture tests
run: npm run test:unit
20 changes: 13 additions & 7 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -35,7 +35,7 @@ jobs:
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand All @@ -54,7 +54,7 @@ jobs:

- name: Upload coverage report
if: matrix.php-version == '8.3'
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
with:
name: coverage-report
path: coverage.xml
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -98,8 +98,12 @@ jobs:
extensions: mbstring, intl, json, mysqli, pdo_mysql
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist --no-progress
# 統合レーン専用ツールチェーン(PHPUnit 9.6 + yoast/phpunit-polyfills ^1.1)。
# WordPress 7.0 テストスイートは PHPUnit 10 で削除された
# parseTestMethodAnnotations() を使うため、テーマ本体の PHPUnit ^11 とは
# 分離した composer manifest からインストールする。
- name: Install integration test toolchain (PHPUnit 9.6 + polyfills)
run: composer install --working-dir=tests/integration-tooling --prefer-dist --no-progress

- name: Install WordPress test suite
run: |
Expand Down Expand Up @@ -153,6 +157,8 @@ jobs:
define('WP_TESTS_TITLE', 'Test Blog');
define('WP_PHP_BINARY', 'php');
define('WPLANG', '');
// 統合ツールチェーンの polyfills を WP テストスイートに明示(読込順に依存しない)
define('WP_TESTS_PHPUNIT_POLYFILLS_PATH', '$GITHUB_WORKSPACE/tests/integration-tooling/vendor/yoast/phpunit-polyfills');
EOF

# テーマをWordPressにシンボリックリンク
Expand All @@ -164,4 +170,4 @@ jobs:
- name: Run integration tests
env:
WP_TESTS_DIR: /tmp/wordpress-tests-lib
run: vendor/bin/phpunit --testsuite integration --colors=always
run: tests/integration-tooling/vendor/bin/phpunit -c phpunit-integration.xml.dist --colors=always
2 changes: 1 addition & 1 deletion .github/workflows/pot_generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
WP_POT_Generator:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: Wordpress POT Generation
shell: bash
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ claudedocs
# Composer
vendor/
composer.lock
# 統合テスト用ツールチェーンは再現性のため lock を追跡する
!tests/integration-tooling/composer.lock

# PHPUnit
.phpunit.cache/
.phpunit.result.cache
tests/coverage/
configs/

Expand Down
153 changes: 153 additions & 0 deletions bin/run-integration-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/usr/bin/env bash
#
# WordPress 統合テスト(integration レーン)をローカルの Docker で実行する。
#
# 概要:
# ユニットレーン(PHPUnit 11 / Brain\Monkey)とは分離した統合レーンを、
# 実 WordPress 環境で実行する。統合レーンは WordPress 7.0 テストスイートが
# 要求する PHPUnit 9.6 + yoast/phpunit-polyfills ^1.1(tests/integration-tooling)
# を使い、bootstrap は WP_UnitTestCase をロードする tests/Integration/bootstrap.php。
#
# 実行経路は .github/workflows/phpunit.yml の integration-tests ジョブと同一:
# 1. WordPress コア + wordpress-develop テストスイートを取得
# 2. wp-tests-config.php を生成(テスト用 DB を指す)
# 3. tests/integration-tooling で composer install(PHPUnit 9.6 + polyfills)
# 4. phpunit-integration.xml.dist で integration testsuite を実行
#
# 前提:
# - Docker / Docker Compose が利用可能なこと
# - テスト用 MySQL は docker/docker-compose.wp7.0-php8.4.yml で起動する
# (初期化 SQL で DB "wordpress_test" を作成済み)
#
# 環境変数(すべて任意・上書き可能):
# WP_VERSION テスト対象の WordPress バージョン (default: 7.0.1)
# COCOON_PHP_IMAGE PHP ランタイムとして使う Docker イメージ (default: wordpress:7.0-php8.4-apache)
# COCOON_COMPOSE_FILE MySQL を起動する compose ファイル
# COCOON_MYSQL_SERVICE compose 内の MySQL サービス名
# COCOON_DOCKER_NETWORK テスト実行コンテナを接続する Docker ネットワーク
# COCOON_DB_HOST/NAME/USER/PASSWORD テスト用 DB 接続情報
# COCOON_WORK_VOLUME WP コア/テストスイートを保持する Docker ボリューム名
# http_proxy/https_proxy 設定されていればコンテナへ引き継ぐ(企業プロキシ等)
#
# 追加引数はそのまま phpunit に渡される。例:
# bin/run-integration-tests.sh --filter NoticeTest
# UPDATE_GOLDEN=1 bin/run-integration-tests.sh --filter NewListBlockRenderTest
#
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"

# --- 設定 ---
WP_VERSION="${WP_VERSION:-7.0.1}"
PHP_IMAGE="${COCOON_PHP_IMAGE:-wordpress:7.0-php8.4-apache}"
COMPOSE_FILE="${COCOON_COMPOSE_FILE:-$REPO_DIR/docker/docker-compose.wp7.0-php8.4.yml}"
MYSQL_SERVICE="${COCOON_MYSQL_SERVICE:-mysql-7-0-php84}"
DOCKER_NETWORK="${COCOON_DOCKER_NETWORK:-docker_cocoon-70-php84-network}"
DB_HOST="${COCOON_DB_HOST:-$MYSQL_SERVICE}"
DB_NAME="${COCOON_DB_NAME:-wordpress_test}"
DB_USER="${COCOON_DB_USER:-root}"
DB_PASSWORD="${COCOON_DB_PASSWORD:-rootpassword}"
WORK_VOLUME="${COCOON_WORK_VOLUME:-cocoon_integration_work}"

COMPOSE="docker compose -f $COMPOSE_FILE"

echo "== [1/4] テスト用 MySQL を起動 ($MYSQL_SERVICE) =="
$COMPOSE up -d "$MYSQL_SERVICE"

echo "== MySQL の healthy を待機 =="
for _ in $(seq 1 30); do
status="$(docker inspect -f '{{.State.Health.Status}}' "$($COMPOSE ps -q "$MYSQL_SERVICE")" 2>/dev/null || echo starting)"
[ "$status" = "healthy" ] && break
sleep 2
done
echo " MySQL status: ${status:-unknown}"

# --- コンテナへ渡すプロキシ設定(任意) ---
PROXY_ARGS=()
if [ -n "${http_proxy:-}" ]; then PROXY_ARGS+=(-e "http_proxy=${http_proxy}"); fi
if [ -n "${https_proxy:-}" ]; then PROXY_ARGS+=(-e "https_proxy=${https_proxy}"); fi
PROXY_ARGS+=(-e "no_proxy=${no_proxy:-$DB_HOST,localhost,127.0.0.1}")

# --- コンテナ内で実行するセットアップ + テスト ---
# 変数はホスト側で展開して埋め込む。
INNER=$(cat <<INNER_EOF
set -euo pipefail
WORK=/work
WP_CORE_DIR="\$WORK/wordpress"
WP_TESTS_DIR="\$WORK/wordpress-tests-lib"
WP_VERSION="$WP_VERSION"

mkdir -p "\$WORK"

# --- WordPress コア ---
if [ ! -f "\$WP_CORE_DIR/wp-load.php" ]; then
echo "== WordPress コア \$WP_VERSION を取得 =="
mkdir -p "\$WP_CORE_DIR"
curl -sSL "https://wordpress.org/wordpress-\${WP_VERSION}.tar.gz" | tar xz --strip-components=1 -C "\$WP_CORE_DIR"
fi

# --- wordpress-develop テストスイート (includes + data) ---
if [ ! -f "\$WP_TESTS_DIR/includes/functions.php" ]; then
echo "== wordpress-develop テストスイート \$WP_VERSION を取得 =="
mkdir -p "\$WP_TESTS_DIR"
tmptar="\$WORK/wp-develop.tar.gz"
curl -sSL "https://codeload.github.com/WordPress/wordpress-develop/tar.gz/refs/tags/\${WP_VERSION}" -o "\$tmptar"
tar xz -C "\$WORK" -f "\$tmptar" \
"wordpress-develop-\${WP_VERSION}/tests/phpunit/includes" \
"wordpress-develop-\${WP_VERSION}/tests/phpunit/data"
mv "\$WORK/wordpress-develop-\${WP_VERSION}/tests/phpunit/includes" "\$WP_TESTS_DIR/includes"
mv "\$WORK/wordpress-develop-\${WP_VERSION}/tests/phpunit/data" "\$WP_TESTS_DIR/data"
rm -rf "\$WORK/wordpress-develop-\${WP_VERSION}" "\$tmptar"
fi

# --- wp-tests-config.php ---
cat > "\$WP_TESTS_DIR/wp-tests-config.php" <<CFG
<?php
define('ABSPATH', '\$WP_CORE_DIR/');
define('DB_NAME', '$DB_NAME');
define('DB_USER', '$DB_USER');
define('DB_PASSWORD', '$DB_PASSWORD');
define('DB_HOST', '$DB_HOST');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
\\\$table_prefix = 'wptests_';
define('WP_TESTS_DOMAIN', 'example.org');
define('WP_TESTS_EMAIL', 'admin@example.org');
define('WP_TESTS_TITLE', 'Test Blog');
define('WP_PHP_BINARY', 'php');
define('WPLANG', '');
CFG

# --- テーマを WP コアへシンボリックリンク(テーマ名 = cocoon-master) ---
mkdir -p "\$WP_CORE_DIR/wp-content/themes"
rm -f "\$WP_CORE_DIR/wp-content/themes/cocoon-master"
ln -s /theme "\$WP_CORE_DIR/wp-content/themes/cocoon-master"

# --- composer 取得 & 統合ツールチェーンの依存インストール ---
if [ ! -f "\$WORK/composer.phar" ]; then
echo "== composer を取得 =="
curl -sSL https://getcomposer.org/download/latest-stable/composer.phar -o "\$WORK/composer.phar"
fi
echo "== composer install (tests/integration-tooling) =="
php "\$WORK/composer.phar" install --working-dir=/theme/tests/integration-tooling \
--prefer-dist --no-progress --no-interaction 2>&1 | tail -5

# --- 統合レーン実行 ---
echo "== integration テストを実行 =="
cd /theme
export WP_TESTS_DIR="\$WP_TESTS_DIR"
exec tests/integration-tooling/vendor/bin/phpunit -c phpunit-integration.xml.dist --colors=always $*
INNER_EOF
)

echo "== [2/4] PHP ランタイムコンテナ ($PHP_IMAGE) で実行 =="
docker run --rm \
--network "$DOCKER_NETWORK" \
"${PROXY_ARGS[@]}" \
${UPDATE_GOLDEN:+-e UPDATE_GOLDEN="$UPDATE_GOLDEN"} \
-v "$REPO_DIR":/theme \
-v "$WORK_VOLUME":/work \
-w /theme \
"$PHP_IMAGE" \
bash -c "$INNER"
27 changes: 27 additions & 0 deletions blocks/jest-unit.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* jest(wp-scripts test-unit-js)用の設定。
*
* @wordpress/scripts の既定プリセット(@wordpress/jest-preset-default)を土台に、
* Cocoon 固有のグローバルスタブ(setup-cocoon-globals.js)を setupFiles に追加し、
* 本番ビルドで外部化される `@wordpress/editor` をテスト用スタブに解決する。
*/
const path = require( 'path' );
const defaultConfig = require( '@wordpress/scripts/config/jest-unit.config.js' );
const presetSetupFiles =
require( '@wordpress/jest-preset-default/jest-preset.js' ).setupFiles || [];

module.exports = {
...defaultConfig,
setupFiles: [
...presetSetupFiles,
require.resolve( './jest/setup-cocoon-globals.js' ),
],
moduleNameMapper: {
...( defaultConfig.moduleNameMapper || {} ),
// 本番では wp.editor グローバルに外部化される(devDep に無い)。
'^@wordpress/editor$': path.resolve(
__dirname,
'jest/stubs/wordpress-editor.js'
),
},
};
Loading