Skip to content

Commit

Permalink
Merge pull request #637 from lucatume/fix-583
Browse files Browse the repository at this point in the history
fix(WPTestCase) call _after method correctly
  • Loading branch information
lucatume authored Sep 21, 2023
2 parents 0049ff9 + d5962f6 commit 3a8080c
Show file tree
Hide file tree
Showing 14 changed files with 451 additions and 406 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ jobs:
context: containers/php
file: containers/php/Dockerfile-PHP-5.6
push: false
tags: lucatume/wp-browser-v3-build:php5.6-apache
tags: lucatume/wp-browser-v3-wordpress:php5.6-apache
cache-from: type=gha,scope=5.6
cache-to: type=gha,mode=max,scope=5.6
load: true
build-args: |
PHP_VERSION=5.6
WP_IMAGE_VERSION=5
Expand All @@ -35,9 +36,10 @@ jobs:
context: containers/php
file: containers/php/Dockerfile-PHP-5.6
push: false
tags: lucatume/wp-browser-v3-build:php5.6-codeception
tags: lucatume/wp-browser-v3-codecept:php5.6
cache-from: type=gha,scope=5.6
cache-to: type=gha,mode=max,scope=5.6
load: true
build-args: |
PHP_VERSION=5.6
WP_IMAGE_VERSION=5
Expand Down Expand Up @@ -70,14 +72,15 @@ jobs:
uses: docker/build-push-action@v4
with:
context: containers/php
file: containers/php/Dockerfile
file: containers/php/Dockerfile-PHP-5.6
push: false
tags: lucatume/wp-browser-v3-build:php${{ matrix.php_version }}-apache
cache-from: type=gha,scope=${{ matrix.php_version }}
cache-to: type=gha,mode=max,scope=${{ matrix.php_version }}
tags: lucatume/wp-browser-v3-wordpress:php5.6-apache
cache-from: type=gha,scope=5.6
cache-to: type=gha,mode=max,scope=5.6
load: true
build-args: |
PHP_VERSION=${{ matrix.php_version }}
WP_IMAGE_VERSION=6
PHP_VERSION=5.6
WP_IMAGE_VERSION=5
TARGET=wordpress
USER_UID=33
USER_GID=33
Expand All @@ -88,9 +91,10 @@ jobs:
context: containers/php
file: containers/php/Dockerfile
push: false
tags: lucatume/wp-browser-v3-build:php${{ matrix.php_version }}-codeception
tags: lucatume/wp-browser-v3-codecept:php${{ matrix.php_version }}
cache-from: type=gha,scope=${{ matrix.php_version }}
cache-to: type=gha,mode=max,scope=${{ matrix.php_version }}
load: true
build-args: |
PHP_VERSION=${{ matrix.php_version }}
WP_IMAGE_VERSION=6
Expand All @@ -99,7 +103,7 @@ jobs:
USER_GID=33
USER_NAME=www-data
- name: Build
run: bin/stack -p${{ matrix.php_version }} build
run: bin/stack -p5.6 build
- name: Cache Composer dependencies
uses: actions/cache@v3
with:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

### Fixed

- Ensure `_before` and `_after` methods are called correctly by `WPTestCase`.

## [3.2.0] 2023-09-15;

### Breaking change
Expand Down
71 changes: 6 additions & 65 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
build:
bin/stack build_images
bin/stack -p5.6 build
bin/stack -p7.0 build
bin/stack -p7.1 build
bin/stack -p7.2 build
bin/stack -p7.3 build
bin/stack -p7.4 build
bin/stack -p8.0 build
bin/stack -p8.1 build
.PHONY: build

build_images:
bin/stack -p5.6 build_images
bin/stack -p7.0 build_images
bin/stack -p7.1 build_images
bin/stack -p7.2 build_images
bin/stack -p7.3 build_images
bin/stack -p7.4 build_images
bin/stack -p8.0 build_images
bin/stack -p8.1 build_images

build_56_lock_files:
[ -d config/composer ] || mkdir config/composer
rm -f config/composer/*5.6*
Expand All @@ -40,46 +24,6 @@ build_56_lock_files:

mv config/composer/composer.json.bak composer.json

build_74_lock_files:
[ -d config/composer ] || mkdir config/composer
cp composer.json config/composer/composer.json.bak

bin/stack -p7.4 -d -c2 composer_update
mv composer.json config/composer/composer-7.4-codeception-2.json
mv composer.lock config/composer/composer-7.4-codeception-2.lock
cp config/composer/composer.json.bak composer.json

bin/stack -p7.4 -d -c3 composer_update
mv composer.json config/composer/composer-7.4-codeception-3.json
mv composer.lock config/composer/composer-7.4-codeception-3.lock
cp config/composer/composer.json.bak composer.json

bin/stack -p7.4 -d -c4 composer_update
mv composer.json config/composer/composer-7.4-codeception-4.json
mv composer.lock config/composer/composer-7.4-codeception-4.lock

mv config/composer/composer.json.bak composer.json

build_80_lock_files:
[ -d config/composer ] || mkdir config/composer
cp composer.json config/composer/composer.json.bak

bin/stack -p8.0 -d -c4 composer_update
mv composer.json config/composer/composer-8.0-codeception-4.json
mv composer.lock config/composer/composer-8.0-codeception-4.lock

mv config/composer/composer.json.bak composer.json

build_81_lock_files:
[ -d config/composer ] || mkdir config/composer
cp composer.json config/composer/composer.json.bak

bin/stack -p8.1 -d -c4 composer_update
mv composer.json config/composer/composer-8.1-codeception-4.json
mv composer.lock config/composer/composer-8.1-codeception-4.lock

mv config/composer/composer.json.bak composer.json

lint:
docker run --rm \
--volume "$(PWD):$(PWD):ro" \
Expand Down Expand Up @@ -140,14 +84,11 @@ static_analysis: lint phpcs phpstan
.PHONE: static_analysis

test: static_analysis
bin/stack -p5.6 xdebug-off && bin/stack -c2 composer_update && bin/stack -p5.6 test
bin/stack -p5.6 xdebug-off && bin/stack -c3 composer_update && bin/stack -p5.6 test
bin/stack -p5.6 xdebug-off && bin/stack -c4 composer_update && bin/stack -p5.6 test
bin/stack -p7.4 xdebug-off && bin/stack -c2 composer_update && bin/stack -p7.4 test
bin/stack -p7.4 xdebug-off && bin/stack -c3 composer_update && bin/stack -p7.4 test
bin/stack -p7.4 xdebug-off && bin/stack -c4 composer_update && bin/stack -p7.4 test
bin/stack -p8.0 xdebug-off && bin/stack -c4 composer_update && bin/stack -p8.0 test
bin/stack -p8.1 xdebug-off && bin/stack -c4 composer_update && bin/stack -p8.1 test
bin/stack -p5.6 xdebug-off && bin/stack composer_update && bin/stack -p5.6 test
bin/stack -p7.4 xdebug-off && bin/stack composer_update && bin/stack -p7.4 test
bin/stack -p8.0 xdebug-off && bin/stack composer_update && bin/stack -p8.0 test
bin/stack -p8.1 xdebug-off && bin/stack composer_update && bin/stack -p8.1 test
bin/stack -p8.2 xdebug-off && bin/stack composer_update && bin/stack -p8.2 test
.PHONY: test

clean:
Expand Down
78 changes: 37 additions & 41 deletions bin/stack
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ export USER_GID=$(id -g)
export USER_NAME=$(id -un)
export PWD="$(pwd)"

if [[ "${PHP_VERSION}" =~ ^(5.6|7.0|7.1|7.2|7.3)$ ]]; then
export WORDPRESS_VERSION=5
else
export WORDPRESS_VERSION=6
fi

# If the current architecture is arm64, use the arm64v8 images.
if [ "$(arch)" = "arm64" ]; then
export DOCKER_CHROME_IMAGE="seleniarm/standalone-chromium:116.0-20230828"
Expand Down Expand Up @@ -154,10 +160,10 @@ function ensure_wordpress_scaffolded() {

function run_wp_cli_command() {
docker run --rm -v "${PWD}/var/wordpress:/var/www/html" \
--network "wpbrowser_php_${PHP_VERSION}" \
--network "wpbrowser_v3" \
-w /var/www/html \
-u "${USER_UID}:${USER_GID}" \
"lucatume/wp-browser-v3-build:php${PHP_VERSION}-apache" \
"lucatume/wp-browser-v3-wordpress:php5.6-apache" \
wp --allow-root --url=http://wordpress.test --path=/var/www/html "$@"
}

Expand All @@ -175,10 +181,10 @@ function ensure_wordpress_configured() {
# If the var/wordpress/wp-config.php file is not found, configure WordPress using wp-cli.
# Configure WordPress using wp-cli.
if ! docker run --rm -v "${PWD}/var/wordpress:/var/www/html" \
--network "wpbrowser_php_${PHP_VERSION}" \
--network "wpbrowser_v3" \
-w /var/www/html \
-u "${USER_UID}:${USER_GID}" \
"lucatume/wp-browser-v3-build:php${PHP_VERSION}-apache" \
"lucatume/wp-browser-v3-wordpress:php5.6-apache" \
bash -c "wp --allow-root core config --dbname=wordpress --dbuser=root --dbpass=password --dbhost=database --dbprefix=wp_ --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
Expand Down Expand Up @@ -233,27 +239,12 @@ function ensure_externals_unblocked() {
}

function build_images() {
if [ "${PHP_VERSION}" = "5.6" ]; then
export DOCKERFILE_SUFFIX="-PHP-5.6"
fi

if [ "${PHP_VERSION}" = "5.6" ]; then
export WP_IMAGE_VERSION="5"
else
export WP_IMAGE_VERSION="6"
fi

docker compose build --build-arg "WP_IMAGE_VERSION=${WP_IMAGE_VERSION}" --progress plain wordpress || exit 1
docker compose build --build-arg "WP_IMAGE_VERSION=${WP_IMAGE_VERSION}" --progress plain codecept || exit 1
docker compose build || exit 1
}

function build() {
[ ! -d "${PWD}/var/cache/composer" ] && mkdir -p "${PWD}/var/cache/composer"
docker compose pull --ignore-buildable || exit 1
# Skip building the images if SKIP_BUILD is 1.
if [ "${SKIP_BUILD}" = "0" ]; then
build_images
fi
docker compose up -d --force-recreate --wait database || exit 1
ensure_wordpress_scaffolded
ensure_wordpress_configured
Expand All @@ -262,7 +253,12 @@ function build() {
ensure_wordpress_updated
docker compose up -d --wait wordpress
docker compose up -d --wait chrome
docker compose up -d --wait codecept

# Up all the Codecept versions.
for version in "${SUPPORTED_PHP_VERSIONS[@]}"; do
docker compose up -d --wait codecept_${version}
done

ensure_test_databases
ensure_twentytwenty_theme
ensure_twentytwentyone_theme
Expand All @@ -271,22 +267,16 @@ function build() {
}

function clean() {
for version in "${SUPPORTED_PHP_VERSIONS[@]}"; do
PHP_VERSION=$version docker compose down -v
PHP_VERSION=$version docker compose rm -f
docker rmi "lucatume/wp-browser-v3-build:php${version}-apache"
docker rmi "lucatume/wp-browser-v3-build:php${version}-codeception"
done
docker compose down -v || true
docker compose rm -f || true
docker rmi $(docker image ls -q lucatume/wp-browser-v3-wordpress) || true
docker rmi $(docker image ls -q lucatume/wp-browser-v3-codecept) || true

rm -rf var/wordpress
rm -rf var && mkdir -p var
}

function clean_tmp() {
if [[ "$OSTYPE" == "darwin"* ]] && [ -f docker-compose.override.yml ] && [ -d /Volumes/WP-Browser-Ram-Disk/ ]; then
rm -rf /Volumes/WP-Browser-Ram-Disk/*
else
rm -rf "$(pwd)/var/tmp"
fi
rm -rf "$(pwd)/var/tmp"
}

function config() {
Expand All @@ -299,7 +289,7 @@ function composer_run() {
-w "$(pwd)" \
--no-deps \
--entrypoint=bash \
codecept -c "composer $*" || exit 1
codecept_${PHP_VERSION} -c "composer $*" || exit 1
}

function composer_update() {
Expand All @@ -320,18 +310,18 @@ function run_tests() {
echo "Running tests for suite $suite ... "
echo "=============================================================================="
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" \
codecept bash -c "php vendor/bin/codecept run $suite --ext DotReporter" || exit 1
codecept_${PHP_VERSION} bash -c "php vendor/bin/codecept run $suite --ext DotReporter" || exit 1
done
}

function xdebug_off() {
docker compose exec -u "$(id -u):$(id -g)" -w "/var/www/html" wordpress bash xdebug-off || exit 1
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept bash xdebug-off || exit 1
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept_${PHP_VERSION} bash xdebug-off || exit 1
}

function xdebug_on() {
docker compose exec -u "$(id -u):$(id -g)" -w "/var/www/html" wordpress bash xdebug-on || exit 1
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)}" codecept bash xdebug-on || exit 1
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)}" codecept_${PHP_VERSION} bash xdebug-on || exit 1
}

COMMAND=${1:-help}
Expand Down Expand Up @@ -376,6 +366,9 @@ down)
;;
exec)
service=${2:-codecept}
if [ $service = 'codecept' ]; then
service="codecept_${PHP_VERSION}"
fi
docker compose exec -u "$(id -u):$(id -g)" -it -w "$(pwd)" "$service" "${@:2}"
;;
help)
Expand All @@ -388,19 +381,22 @@ mysql)
docker compose exec database mysql -u root -ppassword
;;
phpcs)
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept bash -c "composer run cs"
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept_${PHP_VERSION} bash -c "composer run cs"
;;
phpcbf)
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept bash -c "composer run cs-fix"
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept_${PHP_VERSION} bash -c "composer run cs-fix"
;;
phpstan)
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept bash -c "composer run stan"
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept_${PHP_VERSION} bash -c "composer run stan"
;;
ps)
docker compose ps
;;
ssh)
service=${2:-codecept}
if [ $service = "codecept" ]; then
service="codecept_${PHP_VERSION}"
fi
# If ROOT is set, set the user to "0:0", else set the user to the current user.
if [ "${ROOT}" ]; then
docker_user="0:0"
Expand All @@ -411,7 +407,7 @@ ssh)
;;
run)
shift
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept php vendor/bin/codecept run $@
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept_${PHP_VERSION} php vendor/bin/codecept run $@
;;
test)
run_tests
Expand Down
Loading

0 comments on commit 3a8080c

Please sign in to comment.