diff --git a/.travis.yml b/.travis.yml index 229bfcb3..4b35dd14 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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 diff --git a/Dockerfile b/Dockerfile index 350df241..429e8f50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/bin/testing-entrypoint.sh b/bin/testing-entrypoint.sh index c0f335f3..4fb9212f 100644 --- a/bin/testing-entrypoint.sh +++ b/bin/testing-entrypoint.sh @@ -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." @@ -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 \ No newline at end of file diff --git a/codeception.dist.yml b/codeception.dist.yml index 7b0416d4..757cf03c 100644 --- a/codeception.dist.yml +++ b/codeception.dist.yml @@ -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 @@ -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' @@ -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' diff --git a/docker-compose.yml b/docker-compose.yml index 6dbb950d..f1aabbae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 16a39027..00000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,16 +0,0 @@ - - - - - ./tests/ - ./tests/test-sample.php - - - diff --git a/tests/_support/Helper/Acceptance.php b/tests/_support/Helper/Acceptance.php index b37ad378..2a13b6c5 100644 --- a/tests/_support/Helper/Acceptance.php +++ b/tests/_support/Helper/Acceptance.php @@ -316,9 +316,11 @@ class Acceptance extends \Codeception\Module { $rest->haveHttpHeader( 'woocommerce-session', $session_header ); } + $wp_url = getenv( 'WP_URL' ); + // Send request. $rest->sendPOST( - '/graphql', + "{$wp_url}/graphql", json_encode( array( 'query' => $mutation, diff --git a/tests/wpunit.suite.dist.yml b/tests/wpunit.suite.dist.yml index 09b017ee..e53f1db4 100644 --- a/tests/wpunit.suite.dist.yml +++ b/tests/wpunit.suite.dist.yml @@ -9,4 +9,5 @@ modules: - \Helper\Wpunit disabled: - WPDb - - WPBrowser \ No newline at end of file + - WPBrowser +bootstrap: bootstrap.php \ No newline at end of file diff --git a/tests/wpunit/bootstrap.php b/tests/wpunit/bootstrap.php new file mode 100644 index 00000000..10b6bf6a --- /dev/null +++ b/tests/wpunit/bootstrap.php @@ -0,0 +1,4 @@ += 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) { @@ -48,19 +48,19 @@ class ComposerAutoloaderInitcece0dfed0b70a4b4547c45015505517 $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; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 983bce8a..11561ee0 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitcece0dfed0b70a4b4547c45015505517 +class ComposerStaticInit9bbd45aa8b04608575647f29a64a8d55 { public static $files = array ( '914b07b8cf678ed0b81bfdb5d23b4f2b' => __DIR__ . '/../..' . '/includes/connection/common-post-type-args.php', @@ -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); }