Skip to content

Commit

Permalink
Merge pull request #173 from kidunot89/bugfix/codeception-config
Browse files Browse the repository at this point in the history
Testing/CI configurations upgrade.
  • Loading branch information
kidunot89 authored Nov 17, 2019
2 parents 541dc26 + 1945b63 commit 82dbc01
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 67 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ script:
- |
if [ ! -z "$WP_VERSION" ]; then
docker-compose run --rm \
-e SUITES='acceptance;functional;wpunit' \
-e COVERAGE=${COVERAGE:-0} \
-e DEBUG=${DEBUG:-0} \
testing --scale app=0
Expand All @@ -114,6 +113,5 @@ after_success:
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar
chmod +x php-coveralls.phar
sed -i 's/\/var\/www\/html\/wp-content\/plugins\/wp-graphql-woocommerce\///g' tests/_output/coverage.xml
travis_retry php php-coveralls.phar -v
fi
20 changes: 15 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,27 @@ LABEL author_uri=https://github.com/kidunot89

SHELL [ "/bin/bash", "-c" ]

# Redeclare ARGs and set as environmental variables for reuse.
ARG DESIRED_WP_VERSION
ARG DESIRED_PHP_VERSION
ENV WP_VERSION=${DESIRED_WP_VERSION}
ENV PHP_VERSION=${DESIRED_PHP_VERSION}

# Install php extensions
RUN docker-php-ext-install pdo_mysql

# Install Xdebug
RUN if [ "$DESIRED_PHP_VERSION" == "5.6" ]; then yes | pecl install xdebug-2.5.5; else yes | pecl install xdebug; fi \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
# Install PCOV and XDebug
RUN if [ "$PHP_VERSION" != "5.6" ] && [ "$PHP_VERSION" != "7.0" ]; then \
apt-get install zip unzip -y && \
pecl install pcov && \
docker-php-ext-enable pcov && \
rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
echo "pcov.enabled=1" >> /usr/local/etc/php/php.ini ;\
elif [ "$PHP_VERSION" == "5.6" ]; then \
yes | pecl install xdebug-2.5.5; \
else \
yes | pecl install xdebug; \
fi

# Install composer
ENV COMPOSER_ALLOW_SUPERUSER=1
Expand Down
80 changes: 54 additions & 26 deletions bin/testing-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
#!/bin/bash

# Processes parameters and runs Codeception.
run_tests() {
echo "Running Tests"
if [ "$COVERAGE" == "1" ]; then
local coverage="--coverage --coverage-xml"
fi
if [ "$DEBUG" == "1" ]; then
local debug="--debug"
fi

local suites=${1:-" ;"}
IFS=';' read -ra target_suites <<< "$suites"
for suite in "${target_suites[@]}"; do
vendor/bin/codecept run -c codeception.dist.yml ${suite} ${coverage:-} ${debug:-} --no-exit
done
}

# Exits with a status of 0 (true) if provided version number is higher than proceeding numbers.
function version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
}

# Move to WordPress root folder
workdir="$PWD"
echo "Moving to WordPress root directory."
Expand Down Expand Up @@ -30,37 +52,43 @@ fi
# Install dependencies
COMPOSER_MEMORY_LIMIT=-1 composer install --prefer-source --no-interaction

# Install pcov/clobber if PHP7.1+
if version_gt $PHP_VERSION 7.0 && [[ "$COVERAGE" == "1" ]]; then
echo "Installing pcov/clobber"
COMPOSER_MEMORY_LIMIT=-1 composer require --dev pcov/clobber
vendor/bin/pcov clobber
elif [ "$COVERAGE" == "1" ]; then
echo "Sorry, there is no PCOV support for this PHP ${PHP_VERSION} at this time"
fi

# Set output permission
echo "Setting Codeception output directory permissions"
chmod 777 ${TESTS_OUTPUT}

if [[ -z "$SUITES" ]]; then
if [ "$COVERAGE" == "1" -a "$DEBUG" == "1" ]; then
vendor/bin/codecept run --debug --coverage --coverage-xml
elif [ "$COVERAGE" == "1" ]; then
vendor/bin/codecept run --coverage --coverage-xml
elif [ "$DEBUG" == "1" ]; then
vendor/bin/codecept run --debug
else
vendor/bin/codecept run
# Run tests
run_tests ${SUITES}

# Fix codecoverage permissions and clean coverage.xml
if [ -f "${TESTS_OUTPUT}/coverage.xml" ] && [[ "$COVERAGE" == "1" ]]; then
echo 'Setting "coverage.xml" permissions'.
chmod 777 -R "$TESTS_OUTPUT"/coverage.xml

echo 'Cleaning coverage.xml for deployment'.
pattern="$PROJECT_DIR/"
sed -i "s~$pattern~~g" "$TESTS_OUTPUT"/coverage.xml

# Remove pcov/clobber
if version_gt $PHP_VERSION 7.0; then
echo 'Removing pcov/clobber.'
vendor/bin/pcov unclobber
COMPOSER_MEMORY_LIMIT=-1 composer remove --dev pcov/clobber
fi
else
IFS=';' read -ra target_suites <<< "$SUITES"
for suite in "${target_suites[@]}"; do
if [ "$COVERAGE" == "1" -a "$DEBUG" == "1" ]; then
vendor/bin/codecept run ${suite} --debug --coverage --coverage-xml
elif [ "$COVERAGE" == "1" ]; then
vendor/bin/codecept run ${suite} --coverage --coverage-xml
elif [ "$DEBUG" == "1" ]; then
vendor/bin/codecept run ${suite} --debug
else
vendor/bin/codecept run ${suite}
fi
done
fi


if [ -f "${TESTS_OUTPUT}" ]; then
echo 'Setting "coverage.xml" permissions'.
chmod 777 -R ${TESTS_OUTPUT}/coverage.xml
if [ -f "${TESTS_OUTPUT}/failed" ]; then
echo "Uh oh, some went wrong."
exit 1
else
echo "Woohoo! It's working!"
exit 0
fi
22 changes: 18 additions & 4 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ settings:
coverage:
enabled: true
remote: false
work_dir: /var/www/html/wp-content/plugins/wp-graphql-woocommerce
c3_url: http://localhost/wp-content/plugins/wp-graphql-woocommerce/wp-graphql-woocommerce.php
work_dir: '%WP_ROOT_FOLDER%/wp-content/plugins/wp-graphql-woocommerce'
c3_url: '%WP_URL%/wp-content/plugins/wp-graphql-woocommerce/wp-graphql-woocommerce.php'
whitelist:
include:
- wp-graphql-woocommerce.php
- access-functions.php
- class-inflect.php
- includes/*.php
remote_context_options:
http:
timeout: 90
extensions:
enabled:
- Codeception\Extension\RunFailed
Expand Down Expand Up @@ -53,9 +56,12 @@ modules:
adminUsername: '%ADMIN_USERNAME%'
adminPassword: '%ADMIN_PASSWORD%'
adminPath: '/wp-admin'
curl:
CURLOPT_TIMEOUT: 60000
REST:
depends: WPBrowser
url: '%WP_URL%'
timeout: 90
WPFilesystem:
wpRootFolder: '%WP_ROOT_FOLDER%'
plugins: '/wp-content/plugins'
Expand All @@ -72,6 +78,14 @@ modules:
domain: '%WP_DOMAIN%'
adminEmail: '%ADMIN_EMAIL%'
title: 'Test'
plugins: ['woocommerce/woocommerce.php', 'wp-graphql/wp-graphql.php', 'wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php', 'wp-graphql-woocommerce/wp-graphql-woocommerce.php']
activatePlugins: ['woocommerce/woocommerce.php', 'wp-graphql/wp-graphql.php', 'wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php', 'wp-graphql-woocommerce/wp-graphql-woocommerce.php']
plugins:
- woocommerce/woocommerce.php
- wp-graphql/wp-graphql.php
- wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php
- wp-graphql-woocommerce/wp-graphql-woocommerce.php
activatePlugins:
- woocommerce/woocommerce.php
- wp-graphql/wp-graphql.php
- wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php
- wp-graphql-woocommerce/wp-graphql-woocommerce.php
configFile: 'tests/_data/config.php'
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
image: "kidunot89/woographql-app:wp${WP_VERSION:-5.2.2}-php${PHP_VERSION:-7.2}"
volumes:
- '.:/var/www/html/wp-content/plugins/wp-graphql-woocommerce'
- './codeception.dist.yml:/var/www/html/wp-content/plugins/wp-graphql-woocommerce/codeception.yml'
- './.log/app:/var/log/apache2'
env_file: .env.dist
environment:
Expand Down
16 changes: 0 additions & 16 deletions phpunit.xml.dist

This file was deleted.

4 changes: 3 additions & 1 deletion tests/_support/Helper/Acceptance.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,11 @@ public function executeQuery( $mutation, $input, $session_header = null, $update
$rest->haveHttpHeader( 'woocommerce-session', $session_header );
}

$wp_url = getenv( 'WP_URL' );

// Send request.
$rest->sendPOST(
'/graphql',
"{$wp_url}/graphql",
json_encode(
array(
'query' => $mutation,
Expand Down
3 changes: 2 additions & 1 deletion tests/wpunit.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ modules:
- \Helper\Wpunit
disabled:
- WPDb
- WPBrowser
- WPBrowser
bootstrap: bootstrap.php
4 changes: 4 additions & 0 deletions tests/wpunit/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

// Turn off "QL_SESSION_HANDLER" for unit tests.
define( 'NO_QL_SESSION_HANDLER', true );
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitcece0dfed0b70a4b4547c45015505517::getLoader();
return ComposerAutoloaderInit9bbd45aa8b04608575647f29a64a8d55::getLoader();
14 changes: 7 additions & 7 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInitcece0dfed0b70a4b4547c45015505517
class ComposerAutoloaderInit9bbd45aa8b04608575647f29a64a8d55
{
private static $loader;

Expand All @@ -19,15 +19,15 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInitcece0dfed0b70a4b4547c45015505517', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit9bbd45aa8b04608575647f29a64a8d55', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitcece0dfed0b70a4b4547c45015505517', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit9bbd45aa8b04608575647f29a64a8d55', 'loadClassLoader'));

$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';

call_user_func(\Composer\Autoload\ComposerStaticInitcece0dfed0b70a4b4547c45015505517::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit9bbd45aa8b04608575647f29a64a8d55::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
Expand All @@ -48,19 +48,19 @@ public static function getLoader()
$loader->register(true);

if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitcece0dfed0b70a4b4547c45015505517::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit9bbd45aa8b04608575647f29a64a8d55::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequirecece0dfed0b70a4b4547c45015505517($fileIdentifier, $file);
composerRequire9bbd45aa8b04608575647f29a64a8d55($fileIdentifier, $file);
}

return $loader;
}
}

function composerRequirecece0dfed0b70a4b4547c45015505517($fileIdentifier, $file)
function composerRequire9bbd45aa8b04608575647f29a64a8d55($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInitcece0dfed0b70a4b4547c45015505517
class ComposerStaticInit9bbd45aa8b04608575647f29a64a8d55
{
public static $files = array (
'914b07b8cf678ed0b81bfdb5d23b4f2b' => __DIR__ . '/../..' . '/includes/connection/common-post-type-args.php',
Expand Down Expand Up @@ -148,9 +148,9 @@ class ComposerStaticInitcece0dfed0b70a4b4547c45015505517
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitcece0dfed0b70a4b4547c45015505517::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitcece0dfed0b70a4b4547c45015505517::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitcece0dfed0b70a4b4547c45015505517::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit9bbd45aa8b04608575647f29a64a8d55::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit9bbd45aa8b04608575647f29a64a8d55::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit9bbd45aa8b04608575647f29a64a8d55::$classMap;

}, null, ClassLoader::class);
}
Expand Down

0 comments on commit 82dbc01

Please sign in to comment.