Skip to content

Commit

Permalink
Merge pull request #6 from AmpersandHQ/add-support-for-integration-tests
Browse files Browse the repository at this point in the history
Add FULL_INSTALL flag so this can be used for integration tests
  • Loading branch information
convenient authored Mar 15, 2021
2 parents 4a133c6 + 4f70d6f commit 82572bc
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 17 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ notifications:
on_error: always

env:
- TEST_GROUP=latest-integration
- TEST_GROUP=latest
- TEST_GROUP=two_three

Expand All @@ -22,10 +23,10 @@ install:
- composer require ampersand/travis-vanilla-magento:"dev-$TRAVIS_BRANCH" || composer require ampersand/travis-vanilla-magento $TRAVIS_BRANCH

script:
- if [[ $TEST_GROUP = two_three ]]; then phpenv versions; phpenv global 7.2; fi
- if [[ $TEST_GROUP = two_three ]]; then NAME=$TEST_GROUP WITH_SAMPLE_DATA=1 VERSION=2.3.3 . ./vendor/bin/travis-install-magento.sh; fi
- if [[ $TEST_GROUP = latest ]]; then sudo apt-get remove elasticsearch -y && curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-amd64.deb && sudo dpkg -i --force-confnew elasticsearch-7.6.2-amd64.deb && sudo chown elasticsearch:elasticsearch /etc/default/elasticsearch && sudo service elasticsearch restart && sleep 5 && curl -XGET 'localhost:9200'; fi
- if [[ $TEST_GROUP = latest ]]; then NAME=$TEST_GROUP WITH_SAMPLE_DATA=1 . ./vendor/bin/travis-install-magento.sh; fi
- if [[ $TEST_GROUP = two_three ]]; then phpenv versions; phpenv global 7.2; fi
- if [[ $TEST_GROUP = two_three ]]; then NAME=$TEST_GROUP WITH_SAMPLE_DATA=1 VERSION=2.3.3 . ./vendor/bin/travis-install-magento.sh; fi
- if [[ $TEST_GROUP = latest ]]; then NAME=$TEST_GROUP WITH_SAMPLE_DATA=1 . ./vendor/bin/travis-install-magento.sh; fi
- if [[ $TEST_GROUP = latest-integration ]]; then NAME=$TEST_GROUP FULL_INSTALL=0 . ./vendor/bin/travis-install-magento.sh; fi
- echo "Travis Run Done"

addons:
Expand Down
19 changes: 19 additions & 0 deletions install-config-mysql.travis-no-rabbitmq.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

return [
'db-host' => '127.0.0.1',
'db-user' => 'root',
'db-password' => '',
'db-name' => 'magento_integration_tests',
'db-prefix' => 'trv_',
'backend-frontname' => 'backend',
'admin-user' => \Magento\TestFramework\Bootstrap::ADMIN_NAME,
'admin-password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
'admin-email' => \Magento\TestFramework\Bootstrap::ADMIN_EMAIL,
'admin-firstname' => \Magento\TestFramework\Bootstrap::ADMIN_FIRSTNAME,
'admin-lastname' => \Magento\TestFramework\Bootstrap::ADMIN_LASTNAME,
];
23 changes: 23 additions & 0 deletions install-config-mysql.travis.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

return [
'db-host' => '127.0.0.1',
'db-user' => 'root',
'db-password' => '',
'db-name' => 'magento_integration_tests',
'db-prefix' => 'trv_',
'backend-frontname' => 'backend',
'admin-user' => \Magento\TestFramework\Bootstrap::ADMIN_NAME,
'admin-password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
'admin-email' => \Magento\TestFramework\Bootstrap::ADMIN_EMAIL,
'admin-firstname' => \Magento\TestFramework\Bootstrap::ADMIN_FIRSTNAME,
'admin-lastname' => \Magento\TestFramework\Bootstrap::ADMIN_LASTNAME,
'amqp-host' => 'localhost',
'amqp-port' => '5672',
'amqp-user' => 'guest',
'amqp-password' => 'guest',
];
53 changes: 40 additions & 13 deletions travis-install-magento.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ DIR_INSTANCES="$DIR_BASE/instances"
NAME=$NAME
NAME=${NAME//[-._]/}

FULL_INSTALL=${FULL_INSTALL:-1}
WITH_SAMPLE_DATA=${WITH_SAMPLE_DATA:-0}
VERSION=$VERSION
VERSION_NO_DOT=${VERSION//[-._]/}
Expand All @@ -26,6 +27,11 @@ BASE_DOMAIN="magento-$NAME.localhost"
BASE_URL="https://$BASE_DOMAIN"

function prepare_php_and_apache() {
if [ "$FULL_INSTALL" -eq "0" ]; then
echo "Not configuring php-fpm and apachec as this is not a full install"
return 0;
fi

printf "\033[92m###### Configuring php fpm and apache ######\n\n\033[0m";
# fpm error logs are found here; /home/travis/.phpenv/versions/7.0.25/var/log/php-fpm.log
sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
Expand All @@ -51,7 +57,7 @@ function prepare_php_and_apache() {

printf "\033[92m###### Updating /etc/hosts ######\n\n\033[0m";

if ! grep -q "127.0.0.1 $BASE_DOMAIN" "/etc/hosts"; then echo "127.0.0.1 $BASE_DOMAIN" | sudo tee -a /etc/hosts; fi;
if ! grep -q "127.0.0.1 $BASE_DOMAIN" "/etc/hosts"; then echo "127.0.0.1 $BASE_DOMAIN" | sudo tee -a /etc/hosts; fi;

printf "\033[92m###### Restarting apache ######\n\n\033[0m";
sudo a2ensite project.dev.conf
Expand Down Expand Up @@ -83,21 +89,26 @@ function install_magento() {
with_sampledata
fi

printf "\033[92m###### Running installation ######\n\n\033[0m";
if [ "$FULL_INSTALL" -eq "1" ]; then
printf "\033[92m###### Running installation ######\n\n\033[0m";

travis_wait 30 php bin/magento setup:install \
--admin-firstname=ampersand --admin-lastname=developer [email protected] \
--admin-user=admin --admin-password=somepassword123 \
--db-name=$DATABASE_NAME --db-user=root --db-host=127.0.0.1\
--backend-frontname=admin \
--base-url=$BASE_URL \
--language=en_GB --currency=GBP --timezone=Europe/London \
--use-rewrites=1

printf "\033[92m###### Running setup upgrade ######\n\n\033[0m";

php bin/magento setup:upgrade
fi

travis_wait 30 php bin/magento setup:install \
--admin-firstname=ampersand --admin-lastname=developer [email protected] \
--admin-user=admin --admin-password=somepassword123 \
--db-name=$DATABASE_NAME --db-user=root --db-host=127.0.0.1\
--backend-frontname=admin \
--base-url=$BASE_URL \
--language=en_GB --currency=GBP --timezone=Europe/London \
--use-rewrites=1

printf "\033[92m###### Running setup upgrade ######\n\n\033[0m";
cp $DIR_BASE/install-config-mysql*.dist dev/tests/integration/etc

php bin/magento setup:upgrade

mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini.bak ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
cd -
}
Expand All @@ -123,12 +134,28 @@ function with_sampledata() {
}

function assert_alive() {
if [ "$FULL_INSTALL" -eq "0" ]; then
echo "Not performing any database checks as this is not a full instance"
return 0;
fi

printf "\033[92m###### Asserting that you can see $BASE_URL with a 200 response ######\n\n\033[0m";
curl -s -k --head $BASE_URL | head -1 | grep 200
printf "\033[92m###### There are the following number of products in the database ######\n\n\033[0m";
mysql -hlocalhost -uroot $DATABASE_NAME -e "select count(*) from catalog_product_entity;"
}

function install_elasticsearch() {
sudo apt-get remove elasticsearch -y
curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-amd64.deb
sudo dpkg -i --force-confnew elasticsearch-7.6.2-amd64.deb
sudo chown elasticsearch:elasticsearch /etc/default/elasticsearch
sudo service elasticsearch restart
sleep 5
curl -XGET 'localhost:9200' | grep "You Know, for Search"
}

install_elasticsearch
install_magento
prepare_php_and_apache
assert_alive
Expand Down

0 comments on commit 82572bc

Please sign in to comment.