Skip to content

Commit

Permalink
Merge pull request #251 from wp-graphql/fix/test-env-vars
Browse files Browse the repository at this point in the history
fix: functional tests not always detecting env vars
  • Loading branch information
jasonbahl authored Feb 27, 2025
2 parents ef88bd1 + beb7524 commit c589bfa
Show file tree
Hide file tree
Showing 9 changed files with 869 additions and 823 deletions.
25 changes: 25 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# WordPress Test Environment
TEST_SITE_WP_URL=http://localhost:8080
TEST_SITE_DB_HOST=localhost
TEST_SITE_DB_NAME=wordpress_test
TEST_SITE_DB_USER=root
TEST_SITE_DB_PASSWORD=password
TEST_SITE_TABLE_PREFIX=wp_
WP_URL=http://localhost:8080
TEST_SITE_ADMIN_USERNAME=admin
TEST_SITE_ADMIN_PASSWORD=password

# ACF Configuration
ACF_VERSION=latest
ACF_PRO=1
ACF_LICENSE_KEY=your_license_key_here
ACF_EXTENDED_LICENSE_KEY=your_extended_license_key_here

# PHP and WordPress Configuration
PHP_VERSION=8.0
WP_VERSION=6.1
COVERAGE=0
USING_XDEBUG=0
DEBUG=1
SKIP_TESTS_CLEANUP=0
WPGRAPHQL_CONTENT_BLOCKS=0
46 changes: 26 additions & 20 deletions .github/workflows/testing-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,35 @@ jobs:
cp .env.dist .env
cp .env.testing.dist .env.testing
- name: Build and run tests
- name: Build test environment
env:
PHP_VERSION: ${{ matrix.php }}
WP_VERSION: ${{ matrix.wordpress }}
# NOTE: We test against WPGraphQL Content Blocks if ACF Pro is active
run: |
docker-compose build \
--build-arg WP_VERSION=${{ matrix.wordpress }} \
--build-arg PHP_VERSION=${{ matrix.php }} \
--build-arg DOCKER_REGISTRY=ghcr.io/wp-graphql/
docker-compose run \
-e PHP_VERSION=${{ matrix.php }} \
-e WP_VERSION=${{ matrix.wordpress }} \
-e COVERAGE=${{ matrix.coverage }} \
-e USING_XDEBUG=${{ matrix.coverage }} \
-e DEBUG=${{ matrix.debug }} \
-e SKIP_TESTS_CLEANUP=${{ matrix.coverage }} \
-e ACF_PRO=${{matrix.acf_pro }} \
-e ACF_LICENSE_KEY=${{secrets.ACF_LICENSE_KEY}} \
-e ACF_VERSION=${{matrix.acf_version}} \
-e ACF_EXTENDED_LICENSE_KEY=${{secrets.ACF_EXTENDED_LICENSE_KEY}} \
-e WPGRAPHQL_CONTENT_BLOCKS=${{matrix.wpgraphql_content_blocks}} \
testing
COVERAGE: ${{ matrix.coverage }}
USING_XDEBUG: ${{ matrix.coverage }}
DEBUG: ${{ secrets.ACTIONS_STEP_DEBUG || matrix.debug }}
SKIP_TESTS_CLEANUP: ${{ matrix.coverage }}
ACF_PRO: ${{matrix.acf_pro }}
ACF_LICENSE_KEY: ${{secrets.ACF_LICENSE_KEY}}
ACF_VERSION: ${{matrix.acf_version}}
ACF_EXTENDED_LICENSE_KEY: ${{secrets.ACF_EXTENDED_LICENSE_KEY}}
WPGRAPHQL_CONTENT_BLOCKS: ${{matrix.wpgraphql_content_blocks}}
run: composer build-test

- name: Run tests
run: composer run-test
env:
PHP_VERSION: ${{ matrix.php }}
WP_VERSION: ${{ matrix.wordpress }}
COVERAGE: ${{ matrix.coverage }}
USING_XDEBUG: ${{ matrix.coverage }}
DEBUG: 1
SKIP_TESTS_CLEANUP: ${{ matrix.coverage }}
ACF_PRO: ${{matrix.acf_pro }}
ACF_LICENSE_KEY: ${{secrets.ACF_LICENSE_KEY}}
ACF_VERSION: ${{matrix.acf_version}}
ACF_EXTENDED_LICENSE_KEY: ${{secrets.ACF_EXTENDED_LICENSE_KEY}}
WPGRAPHQL_CONTENT_BLOCKS: ${{matrix.wpgraphql_content_blocks}}

- name: Push Codecoverage to Coveralls.io
if: ${{ matrix.coverage == 1 }}
Expand Down
2 changes: 1 addition & 1 deletion bin/run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ case "$subcommand" in
;;
t )
source .env.testing
docker-compose run --rm testing
docker compose run --rm testing
;;
\? ) print_usage_instructions;;
* ) print_usage_instructions;;
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"install-test-env": "bash bin/install-test-env.sh",
"docker-build": "bash bin/run-docker.sh build",
"docker-run": "bash bin/run-docker.sh run",
"docker-destroy": "docker-compose down",
"docker-destroy": "docker compose down",
"build-and-run": [
"@docker-build",
"@docker-run"
Expand All @@ -79,7 +79,10 @@
"composer install"
],
"run-app": "@docker-run -a",
"run-test": "@docker-run -t",
"run-test": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\"",
"bash bin/run-docker.sh run -t"
],
"lint": "vendor/bin/phpcs",
"phpcs-i": [
"php ./vendor/bin/phpcs -i"
Expand Down
Loading

0 comments on commit c589bfa

Please sign in to comment.