Adjust used Docker container to run integration tests
[MAILPOET-4251]
This commit is contained in:
@ -4,7 +4,7 @@ WP_TEST_MAILER_ENABLE_SENDING=true
|
|||||||
WP_TEST_ENABLE_NETWORK_TESTS=true
|
WP_TEST_ENABLE_NETWORK_TESTS=true
|
||||||
|
|
||||||
# Optional: for multisite acceptance tests
|
# Optional: for multisite acceptance tests
|
||||||
WP_ROOT_MULTISITE=/var/www/wordpress
|
WP_ROOT_MULTISITE=/var/www/html
|
||||||
WP_TEST_MULTISITE_SLUG=
|
WP_TEST_MULTISITE_SLUG=
|
||||||
HTTP_HOST= # URL of your site (used for multisite env, equals to DOMAIN_CURRENT_SITE from wp-config.php)
|
HTTP_HOST= # URL of your site (used for multisite env, equals to DOMAIN_CURRENT_SITE from wp-config.php)
|
||||||
|
|
||||||
|
@ -180,36 +180,13 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
return $this->_exec($command);
|
return $this->_exec($command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIntegration(array $opts = ['file' => null, 'xml' => false, 'multisite' => false, 'debug' => false]) {
|
public function testIntegration(array $opts = ['file' => null, 'xml' => false, 'multisite' => false, 'debug' => false, 'skip-deps' => false]) {
|
||||||
if (getenv('MAILPOET_DEV_SITE')) {
|
return $this->runTestsInContainer(array_merge($opts, ['test_type' => 'integration']));
|
||||||
$run = $this->confirm("You are about to run tests on the development site. Your DB data will be erased. \nDo you want to proceed?", false);
|
|
||||||
if (!$run) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$command = 'vendor/bin/codecept run integration -vvv';
|
|
||||||
|
|
||||||
if ($opts['multisite']) {
|
|
||||||
$command = 'MULTISITE=true ' . $command;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($opts['file']) {
|
public function testMultisiteIntegration($opts = ['file' => null, 'xml' => false, 'multisite' => true, 'skip-deps' => false]) {
|
||||||
$command .= ' -f ' . $opts['file'];
|
return $this->runTestsInContainer(array_merge($opts, ['test_type' => 'integration']));
|
||||||
}
|
|
||||||
|
|
||||||
if ($opts['xml']) {
|
|
||||||
$command .= ' --xml';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($opts['debug']) {
|
|
||||||
$command .= ' --debug';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->_exec($command);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testMultisiteIntegration($opts = ['file' => null, 'xml' => false, 'multisite' => true]) {
|
|
||||||
return $this->testIntegration($opts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCoverage($opts = ['file' => null, 'xml' => false]) {
|
public function testCoverage($opts = ['file' => null, 'xml' => false]) {
|
||||||
@ -272,24 +249,11 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testAcceptance($opts = ['file' => null, 'skip-deps' => false, 'timeout' => null]) {
|
public function testAcceptance($opts = ['file' => null, 'skip-deps' => false, 'timeout' => null]) {
|
||||||
return $this->taskExec(
|
return $this->runTestsInContainer($opts);
|
||||||
'COMPOSE_HTTP_TIMEOUT=200 docker-compose run ' .
|
|
||||||
($opts['skip-deps'] ? '-e SKIP_DEPS=1 ' : '') .
|
|
||||||
($opts['timeout'] ? '-e WAIT_TIMEOUT=' . (int)$opts['timeout'] . ' ' : '') .
|
|
||||||
'codeception --steps --debug -vvv ' .
|
|
||||||
'-f ' . ($opts['file'] ? $opts['file'] : '')
|
|
||||||
)->dir(__DIR__ . '/tests/docker')->run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAcceptanceMultisite($opts = ['file' => null, 'skip-deps' => false, 'timeout' => null]) {
|
public function testAcceptanceMultisite($opts = ['file' => null, 'skip-deps' => false, 'timeout' => null]) {
|
||||||
return $this->taskExec(
|
return $this->runTestsInContainer(array_merge($opts, ['multisite' => true]));
|
||||||
'COMPOSE_HTTP_TIMEOUT=200 docker-compose run ' .
|
|
||||||
($opts['skip-deps'] ? '-e SKIP_DEPS=1 ' : '') .
|
|
||||||
($opts['timeout'] ? '-e WAIT_TIMEOUT=' . (int)$opts['timeout'] . ' ' : '') .
|
|
||||||
'-e MULTISITE=1 ' .
|
|
||||||
'codeception --steps --debug -vvv ' .
|
|
||||||
'-f ' . ($opts['file'] ? $opts['file'] : '')
|
|
||||||
)->dir(__DIR__ . '/tests/docker')->run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteDocker() {
|
public function deleteDocker() {
|
||||||
@ -1181,4 +1145,18 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
'platform' => new $platformClass,
|
'platform' => new $platformClass,
|
||||||
], $configuration);
|
], $configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function runTestsInContainer(array $opts) {
|
||||||
|
$testType = $opts['test_type'] ?? 'acceptance';
|
||||||
|
|
||||||
|
return $this->taskExec(
|
||||||
|
'COMPOSE_HTTP_TIMEOUT=200 docker-compose run ' .
|
||||||
|
(isset($opts['skip-deps']) && $opts['skip-deps'] ? '-e SKIP_DEPS=1 ' : '') .
|
||||||
|
(isset($opts['timeout']) && $opts['timeout'] ? '-e WAIT_TIMEOUT=' . (int)$opts['timeout'] . ' ' : '') .
|
||||||
|
(isset($opts['multisite']) && $opts['multisite'] ? '-e MULTISITE=1 ' : '-e MULTISITE=0 ') .
|
||||||
|
"codeception_{$testType} --steps --debug -vvv " .
|
||||||
|
(isset($opts['xml']) && $opts['xml'] ? '--xml ' : '') .
|
||||||
|
'-f ' . (isset($opts['file']) && $opts['file'] ? $opts['file'] : '')
|
||||||
|
)->dir(__DIR__ . '/tests/docker')->run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,16 @@ chown www-data:www-data wp-content/plugins
|
|||||||
chown www-data:www-data wp-content/uploads
|
chown www-data:www-data wp-content/uploads
|
||||||
chmod 755 wp-content/plugins
|
chmod 755 wp-content/plugins
|
||||||
chmod -R 777 wp-content/uploads
|
chmod -R 777 wp-content/uploads
|
||||||
|
chmod -R 777 /mailhog-data
|
||||||
|
|
||||||
|
# deleting configs in case are set in previous run
|
||||||
|
wp config delete MULTISITE > /dev/null 2>&1
|
||||||
|
wp config delete WP_ALLOW_MULTISITE > /dev/null 2>&1
|
||||||
|
wp config delete SUBDOMAIN_INSTALL > /dev/null 2>&1
|
||||||
|
wp config delete DOMAIN_CURRENT_SITE > /dev/null 2>&1
|
||||||
|
wp config delete PATH_CURRENT_SITE > /dev/null 2>&1
|
||||||
|
wp config delete SITE_ID_CURRENT_SITE > /dev/null 2>&1
|
||||||
|
wp config delete BLOG_ID_CURRENT_SITE > /dev/null 2>&1
|
||||||
|
|
||||||
# disable automatic updates
|
# disable automatic updates
|
||||||
wp config set WP_AUTO_UPDATE_CORE false --raw
|
wp config set WP_AUTO_UPDATE_CORE false --raw
|
||||||
@ -33,13 +43,14 @@ mysqladmin --host=mysql --user=root --password=wordpress drop wordpress --force
|
|||||||
mysqladmin --host=mysql --user=root --password=wordpress create wordpress --force
|
mysqladmin --host=mysql --user=root --password=wordpress create wordpress --force
|
||||||
|
|
||||||
# install WordPress
|
# install WordPress
|
||||||
WP_CORE_INSTALL_PARAMS="--url=test.local --title=tests --admin_user=admin --admin_email=test@test.com --admin_password=password --skip-email"
|
WP_CORE_INSTALL_PARAMS="--url=$HTTP_HOST --title=tests --admin_user=admin --admin_email=test@test.com --admin_password=password --skip-email"
|
||||||
if [[ -z "$MULTISITE" || "$MULTISITE" -eq "0" ]]; then
|
if [[ -z "$MULTISITE" || "$MULTISITE" -eq "0" ]]; then
|
||||||
echo 'Installing WordPress (single site mode)'
|
echo 'Installing WordPress (single site mode)'
|
||||||
wp core install $WP_CORE_INSTALL_PARAMS
|
wp core install $WP_CORE_INSTALL_PARAMS
|
||||||
else
|
else
|
||||||
echo 'Installing WordPress (multisite mode)'
|
echo 'Installing WordPress (multisite mode)'
|
||||||
wp core multisite-install $WP_CORE_INSTALL_PARAMS
|
wp core multisite-install $WP_CORE_INSTALL_PARAMS
|
||||||
|
wp site create --slug=$WP_TEST_MULTISITE_SLUG
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load Composer dependencies
|
# Load Composer dependencies
|
||||||
@ -51,6 +62,8 @@ if [[ -z "${SKIP_DEPS}" ]]; then
|
|||||||
cd - >/dev/null
|
cd - >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# extra plugins are not supported for integration tests yest
|
||||||
|
if [[ $TEST_TYPE == "acceptance" ]]; then
|
||||||
# Install WooCommerce
|
# Install WooCommerce
|
||||||
if [[ ! -d "/wp-core/wp-content/plugins/woocommerce" ]]; then
|
if [[ ! -d "/wp-core/wp-content/plugins/woocommerce" ]]; then
|
||||||
cd /wp-core/wp-content/plugins
|
cd /wp-core/wp-content/plugins
|
||||||
@ -105,6 +118,13 @@ if [[ ! -d "/wp-core/wp-content/plugins/woo-gutenberg-products-block" ]]; then
|
|||||||
unzip -q -o "$WOOCOMMERCE_BLOCKS_ZIP" -d /wp-core/wp-content/plugins/
|
unzip -q -o "$WOOCOMMERCE_BLOCKS_ZIP" -d /wp-core/wp-content/plugins/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# activate all plugins which source code want to access in tests runtime
|
||||||
|
wp plugin activate woocommerce
|
||||||
|
wp plugin activate woocommerce-subscriptions
|
||||||
|
wp plugin activate woocommerce-memberships
|
||||||
|
wp plugin activate woo-gutenberg-products-block
|
||||||
|
fi # end of check for enabling extra plugins
|
||||||
|
|
||||||
# add configuration
|
# add configuration
|
||||||
CONFIG=''
|
CONFIG=''
|
||||||
CONFIG+="define('WP_DEBUG', true);\n"
|
CONFIG+="define('WP_DEBUG', true);\n"
|
||||||
@ -119,12 +139,6 @@ CONFIG+="if (!isset(\$_SERVER['SERVER_NAME'])) \$_SERVER['SERVER_NAME'] = '';\n"
|
|||||||
|
|
||||||
sed -i "s/define( *'WP_DEBUG', false *);/$CONFIG/" /wp-core/wp-config.php
|
sed -i "s/define( *'WP_DEBUG', false *);/$CONFIG/" /wp-core/wp-config.php
|
||||||
|
|
||||||
# activate all plugins which source code want to access in tests runtime
|
|
||||||
wp plugin activate woocommerce
|
|
||||||
wp plugin activate woocommerce-subscriptions
|
|
||||||
wp plugin activate woocommerce-memberships
|
|
||||||
wp plugin activate woo-gutenberg-products-block
|
|
||||||
|
|
||||||
# activate theme
|
# activate theme
|
||||||
wp theme activate twentytwentyone
|
wp theme activate twentytwentyone
|
||||||
|
|
||||||
@ -132,14 +146,18 @@ if [[ $CIRCLE_JOB == *"_oldest"* ]]; then
|
|||||||
wp theme activate twentynineteen
|
wp theme activate twentynineteen
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $TEST_TYPE == "acceptance" ]]; then
|
||||||
# print info about installed plugins
|
# print info about installed plugins
|
||||||
wp plugin get woocommerce
|
wp plugin get woocommerce
|
||||||
wp plugin get woocommerce-subscriptions
|
wp plugin get woocommerce-subscriptions
|
||||||
wp plugin get woocommerce-memberships
|
wp plugin get woocommerce-memberships
|
||||||
wp plugin get woo-gutenberg-products-block
|
wp plugin get woo-gutenberg-products-block
|
||||||
|
fi
|
||||||
# activate MailPoet
|
# activate MailPoet
|
||||||
wp plugin activate mailpoet/mailpoet.php
|
wp plugin activate mailpoet/mailpoet.php
|
||||||
|
if [[ $MULTISITE == "1" ]]; then
|
||||||
|
wp plugin activate mailpoet/mailpoet.php --url=http://test.local/php7_multisite/
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $CIRCLE_JOB == *"_with_premium_"* ]]; then
|
if [[ $CIRCLE_JOB == *"_with_premium_"* ]]; then
|
||||||
# Copy MailPoet Premium to plugin path
|
# Copy MailPoet Premium to plugin path
|
||||||
@ -150,12 +168,11 @@ fi
|
|||||||
|
|
||||||
cd /wp-core/wp-content/plugins/mailpoet
|
cd /wp-core/wp-content/plugins/mailpoet
|
||||||
# Remove Doctrine Annotations (no need since generated metadata are packed)
|
# Remove Doctrine Annotations (no need since generated metadata are packed)
|
||||||
if [[ $CIRCLE_JOB ]]; then
|
if [[ $TEST_TYPE == "acceptance" ]] && [[ $CIRCLE_JOB ]]; then
|
||||||
rm -rf ./vendor-prefixed/doctrine/annotations
|
rm -rf ./vendor-prefixed/doctrine/annotations
|
||||||
./tools/vendor/composer.phar dump-autoload
|
./tools/vendor/composer.phar dump-autoload
|
||||||
fi
|
fi
|
||||||
|
/project/vendor/bin/codecept run $TEST_TYPE $@
|
||||||
/project/vendor/bin/codecept run acceptance $@
|
|
||||||
exitcode=$?
|
exitcode=$?
|
||||||
|
|
||||||
exit $exitcode
|
exit $exitcode
|
||||||
|
@ -9,7 +9,12 @@ services:
|
|||||||
chrome:
|
chrome:
|
||||||
image: seleniarm/standalone-chromium:4.0.0-20211213
|
image: seleniarm/standalone-chromium:4.0.0-20211213
|
||||||
|
|
||||||
codeception:
|
codeception_acceptance:
|
||||||
|
volumes:
|
||||||
|
- nfs-mailpoet:/project
|
||||||
|
- nfs-mailpoet:/wp-core/wp-content/plugins/mailpoet
|
||||||
|
|
||||||
|
codeception_integration:
|
||||||
volumes:
|
volumes:
|
||||||
- nfs-mailpoet:/project
|
- nfs-mailpoet:/project
|
||||||
- nfs-mailpoet:/wp-core/wp-content/plugins/mailpoet
|
- nfs-mailpoet:/wp-core/wp-content/plugins/mailpoet
|
||||||
|
@ -1,10 +1,35 @@
|
|||||||
version: '3.9'
|
version: '3.9'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
codeception:
|
codeception_acceptance:
|
||||||
image: mailpoet/wordpress:${CODECEPTION_IMAGE_VERSION:-8.0-cli_20220126.1}
|
image: mailpoet/wordpress:${CODECEPTION_IMAGE_VERSION:-8.0-cli_20220126.1}
|
||||||
depends_on:
|
depends_on:
|
||||||
- mailhog
|
- smtp
|
||||||
|
- wordpress
|
||||||
|
- chrome
|
||||||
|
volumes:
|
||||||
|
- wp-core:/wp-core
|
||||||
|
- mailhog-data:/mailhog-data
|
||||||
|
- ../..:/project
|
||||||
|
- ../..:/wp-core/wp-content/plugins/mailpoet
|
||||||
|
- ./codeception/docker-entrypoint.sh:/docker-entrypoint.sh
|
||||||
|
- ../../../dev/php.ini:/usr/local/etc/php/conf.d/php_user.ini
|
||||||
|
- ../../../dev/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
|
||||||
|
entrypoint: /docker-entrypoint.sh
|
||||||
|
environment:
|
||||||
|
WP_ROOT: /wp-core
|
||||||
|
WP_ROOT_MULTISITE: /wp-core
|
||||||
|
WP_TEST_MULTISITE_SLUG: php7_multisite
|
||||||
|
HTTP_HOST: test.local
|
||||||
|
WORDPRESS_DB_PASSWORD: wordpress
|
||||||
|
WORDPRESS_DB_USER: wordpress
|
||||||
|
WORDPRESS_DB_NAME: wordpress
|
||||||
|
WORDPRESS_TABLE_PREFIX: mp_
|
||||||
|
TEST_TYPE: acceptance
|
||||||
|
codeception_integration:
|
||||||
|
image: mailpoet/wordpress:${CODECEPTION_IMAGE_VERSION:-8.0-cli_20220605.0}
|
||||||
|
depends_on:
|
||||||
|
- smtp
|
||||||
- wordpress
|
- wordpress
|
||||||
volumes:
|
volumes:
|
||||||
- wp-core:/wp-core
|
- wp-core:/wp-core
|
||||||
@ -15,12 +40,16 @@ services:
|
|||||||
entrypoint: /docker-entrypoint.sh
|
entrypoint: /docker-entrypoint.sh
|
||||||
environment:
|
environment:
|
||||||
WP_ROOT: /wp-core
|
WP_ROOT: /wp-core
|
||||||
|
WP_ROOT_MULTISITE: /wp-core
|
||||||
|
WP_TEST_MULTISITE_SLUG: php7_multisite
|
||||||
|
HTTP_HOST: test.local
|
||||||
WORDPRESS_DB_PASSWORD: wordpress
|
WORDPRESS_DB_PASSWORD: wordpress
|
||||||
WORDPRESS_DB_USER: wordpress
|
WORDPRESS_DB_USER: wordpress
|
||||||
WORDPRESS_DB_NAME: wordpress
|
WORDPRESS_DB_NAME: wordpress
|
||||||
WORDPRESS_TABLE_PREFIX: mp_
|
WORDPRESS_TABLE_PREFIX: mp_
|
||||||
|
TEST_TYPE: integration
|
||||||
|
|
||||||
mailhog:
|
smtp:
|
||||||
image: mailhog/mailhog:v1.0.0
|
image: mailhog/mailhog:v1.0.0
|
||||||
ports:
|
ports:
|
||||||
- 1025:1025
|
- 1025:1025
|
||||||
@ -35,8 +64,7 @@ services:
|
|||||||
wordpress:
|
wordpress:
|
||||||
image: mailpoet/wordpress:${WORDPRESS_IMAGE_VERSION:-wp-5.9_php8.0_20220127.1}
|
image: mailpoet/wordpress:${WORDPRESS_IMAGE_VERSION:-wp-5.9_php8.0_20220127.1}
|
||||||
depends_on:
|
depends_on:
|
||||||
- chrome
|
- smtp
|
||||||
- mailhog
|
|
||||||
- mysql
|
- mysql
|
||||||
volumes:
|
volumes:
|
||||||
- wp-core:/var/www/html
|
- wp-core:/var/www/html
|
||||||
|
@ -23,10 +23,6 @@ if ((boolean)getenv('MULTISITE') === true) {
|
|||||||
}
|
}
|
||||||
require_once($wpLoadFile);
|
require_once($wpLoadFile);
|
||||||
|
|
||||||
if (!defined('MP_SETTINGS_TABLE')) {
|
|
||||||
die('MailPoet must be activated in the tests site (usually http://localhost:8003) before running the integration tests');
|
|
||||||
}
|
|
||||||
|
|
||||||
$console = new \Codeception\Lib\Console\Output([]);
|
$console = new \Codeception\Lib\Console\Output([]);
|
||||||
$console->writeln('Loading WP core... (' . $wpLoadFile . ')');
|
$console->writeln('Loading WP core... (' . $wpLoadFile . ')');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user