Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: slic testing framework #441

Merged
merged 15 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .env

This file was deleted.

60 changes: 60 additions & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This file will be consumed by both the CI and the tests.
# Some environment variables might not apply to one but might apply to the other: modify with care.

SLIC_PHP_VERSION=8.0

# What version of WordPress we want to install and test against.
# This has to be compatible with the `wp core download` command, see https://developer.wordpress.org/cli/commands/core/download/.
WP_VERSION=latest

# This is where, in the context of the CI, we'll install and configure WordPress.
# See `.travis.yml` for more information.
WP_ROOT_FOLDER=/var/www/html

# The WordPress installation will be served from the Docker container.
# See `dev/docker/ci-compose.yml` for more information.
WP_URL=http://wordpress.test
WP_DOMAIN=wordpress.test
WP_ADMIN_PATH=/wp-admin

# The credentials that will be used to access the site in acceptance tests
# in methods like `$I->loginAsAdmin();`.
WP_ADMIN_USERNAME=admin
WP_ADMIN_PASSWORD=admin

WP_DB_PORT=3306

# The databse is served from the Docker `db` container.
# See `dev/docker/ci-compose.yml` for more information.
WP_TABLE_PREFIX=wp_
WP_DB_HOST=db
WP_DB_NAME=test
WP_DB_USER=root
WP_DB_PASSWORD=password

# The test databse is served from the Docker `db` container.
# See `dev/docker/ci-compose.yml` for more information.
WP_TEST_DB_HOST=db
WP_TEST_DB_NAME=test
WP_TEST_DB_USER=root
WP_TEST_DB_PASSWORD=password

# We're using Selenium and Chrome for acceptance testing.
# In CI context we're starting a Docker container to handle that.
# See the `dev/docker/ci-compose.yml` file.
CHROMEDRIVER_HOST=chrome
CHROMEDRIVER_PORT=4444

# The URL of the WordPress installation from the point of view of the Chromedriver container.
# Why not just use `wordpress`? While Chrome will accept an `http://wordpress` address WordPress
# will not, we call the WordPress container with a seemingly looking legit URL and leverage the
# lines that, in the `wp-config.php` file, will make it so that WordPress will use as its home
# URL whatever URL we reach it with.
# See the `dev/docker/wp-config.php` template for more information.
WP_CHROMEDRIVER_URL=http://wordpress.test

# To run the tests let's force the background-processing lib to run in synchronous (single PHP thread) mode.
TRIBE_NO_ASYNC=1

# We're using Docker to run the tests.
USING_CONTAINERS=1
60 changes: 60 additions & 0 deletions .env.testing.slic
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This file will be consumed by both the CI and the tests.
# Some environment variables might not apply to one but might apply to the other: modify with care.

SLIC_PHP_VERSION=8.0

# What version of WordPress we want to install and test against.
# This has to be compatible with the `wp core download` command, see https://developer.wordpress.org/cli/commands/core/download/.
WP_VERSION=latest

# This is where, in the context of the CI, we'll install and configure WordPress.
# See `.travis.yml` for more information.
WP_ROOT_FOLDER=/var/www/html

# The WordPress installation will be served from the Docker container.
# See `dev/docker/ci-compose.yml` for more information.
WP_URL=http://wordpress.test
WP_DOMAIN=wordpress.test
WP_ADMIN_PATH=/wp-admin

# The credentials that will be used to access the site in acceptance tests
# in methods like `$I->loginAsAdmin();`.
WP_ADMIN_USERNAME=admin
WP_ADMIN_PASSWORD=admin

WP_DB_PORT=3306

# The databse is served from the Docker `db` container.
# See `dev/docker/ci-compose.yml` for more information.
WP_TABLE_PREFIX=wp_
WP_DB_HOST=db
WP_DB_NAME=test
WP_DB_USER=root
WP_DB_PASSWORD=password

# The test databse is served from the Docker `db` container.
# See `dev/docker/ci-compose.yml` for more information.
WP_TEST_DB_HOST=db
WP_TEST_DB_NAME=test
WP_TEST_DB_USER=root
WP_TEST_DB_PASSWORD=password

# We're using Selenium and Chrome for acceptance testing.
# In CI context we're starting a Docker container to handle that.
# See the `dev/docker/ci-compose.yml` file.
CHROMEDRIVER_HOST=chrome
CHROMEDRIVER_PORT=4444

# The URL of the WordPress installation from the point of view of the Chromedriver container.
# Why not just use `wordpress`? While Chrome will accept an `http://wordpress` address WordPress
# will not, we call the WordPress container with a seemingly looking legit URL and leverage the
# lines that, in the `wp-config.php` file, will make it so that WordPress will use as its home
# URL whatever URL we reach it with.
# See the `dev/docker/wp-config.php` template for more information.
WP_CHROMEDRIVER_URL=http://wordpress.test

# To run the tests let's force the background-processing lib to run in synchronous (single PHP thread) mode.
TRIBE_NO_ASYNC=1

# We're using Docker to run the tests.
USING_CONTAINERS=1
16 changes: 16 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Path-based git attributes
# https://mirrors.edge.kernel.org/pub/software/scm/git/docs/gitattributes.html

* text
composer.lock text -diff

# Ignore paths when git creates an archive of this package
/.gitattributes export-ignore
/.gitignore export-ignore
/.github export-ignore
/.editorconfig export-ignore
/.env.testing export-ignore
/.env.testing.slic export-ignore
/codeception.dist.yml export-ignore
/codeception.slic.yml export-ignore
/tests export-ignore
85 changes: 0 additions & 85 deletions .github/workflows/test-php.yml

This file was deleted.

115 changes: 115 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: 'CI'
on:
workflow_dispatch:
pull_request:
push:
jobs:
test:
runs-on: ubuntu-latest

env:
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.COMPOSER_TOKEN }}"}}'

strategy:
matrix:
wordpress:
- latest
- '6.3.3'
- '6.2.4'
php:
- '7.4'
- '8.0'
- '8.1'
- '8.2'

name: WP ${{ matrix.wordpress }} / PHP ${{ matrix.php }}
steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Checkout slic
uses: actions/checkout@v4
with:
repository: stellarwp/slic
ref: 1.5.1
path: slic
fetch-depth: 1

- uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- run: bun install --frozen-lockfile

- name: Build packages
run: bun run build

- name: Get Composer Cache Directory
id: get-composer-cache-dir
run: |
echo "DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
id: composer-cache
with:
path: ${{ steps.get-composer-cache-dir.outputs.DIR }}
key: ${{ matrix.php }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ matrix.php }}-composer-

- name: Set up slic env vars
run: |
echo "SLIC_BIN=${GITHUB_WORKSPACE}/slic/slic" >> $GITHUB_ENV
echo "SLIC_WP_DIR=${GITHUB_WORKSPACE}/slic/_wordpress" >> $GITHUB_ENV
echo "SLIC_WORDPRESS_DOCKERFILE=Dockerfile.base" >> $GITHUB_ENV

- name: Set run context for slic
run: echo "SLIC=1" >> $GITHUB_ENV && echo "CI=1" >> $GITHUB_ENV

- name: Start ssh-agent
run: |
mkdir -p "${HOME}/.ssh";
ssh-agent -a /tmp/ssh_agent.sock;

- name: Export SSH_AUTH_SOCK env var
run: echo "SSH_AUTH_SOCK=/tmp/ssh_agent.sock" >> $GITHUB_ENV

- name: Set up slic for CI
run: |
cd ${GITHUB_WORKSPACE}/..
${SLIC_BIN} here
${SLIC_BIN} interactive off
${SLIC_BIN} build-prompt off
${SLIC_BIN} build-subdir off
${SLIC_BIN} xdebug off
${SLIC_BIN} debug on
${SLIC_BIN} php-version set ${{ matrix.php }} --skip-rebuild
${SLIC_BIN} composer-cache set ${{ steps.get-composer-cache-dir.outputs.DIR }}
${SLIC_BIN} info
${SLIC_BIN} config

- name: Install specific WordPress version
run: |
${SLIC_BIN} wp core download --version=${{ matrix.wordpress }} --force
${SLIC_BIN} wp core version

- name: Set up plugin
run: |
${SLIC_BIN} use kadence-blocks
${SLIC_BIN} composer set-version 2
${SLIC_BIN} composer validate
${SLIC_BIN} composer install

- name: Run wpunit tests
run: ${SLIC_BIN} run wpunit --ext DotReporter

- name: Run acceptance tests
run: ${SLIC_BIN} run acceptance --ext DotReporter

- name: Upload codeception output
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.test }}-${{ matrix.php }}-${{ matrix.wordpress }}-output"
path: "./tests/_output"

6 changes: 0 additions & 6 deletions bin/setup-docker.sh

This file was deleted.

3 changes: 0 additions & 3 deletions bin/test-up.sh

This file was deleted.

17 changes: 0 additions & 17 deletions bin/wait-for-it.sh

This file was deleted.

Loading