Skip to content

Commit

Permalink
First attempt to get functional tests working using magento2 travis f…
Browse files Browse the repository at this point in the history
…iles.
  • Loading branch information
colinmollenhour authored and tmotyl committed May 18, 2020
1 parent 5f228bc commit c57d92c
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 9 deletions.
40 changes: 31 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
sudo: required
dist: trusty
group: edge
addons:
apt:
packages:
- mysql-server-5.6
- mysql-client-core-5.6
- mysql-client-5.6
- postfix
firefox: "46.0"
hosts:
- magento.travis
language: php

php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

env:
global:
- COMPOSER_BIN_DIR=~/bin
- MAGENTO_HOST_NAME="magento.travis"
matrix:
- TEST_SUITE=static
- TEST_SUITE=functional
matrix:
fast_finish: true
allow_failures:
- php: nightly
- php: 7.3
- php: 7.4

cache:
apt: true
directories:
- $HOME/.composer/cache
before_install: ./dev/travis/before_install.sh
install: composer install --no-interaction
before_script: ./dev/travis/before_script.sh
script:
- '! find . -not \( -path ./.phpstorm.meta.php -prune \) -not \( -path ./lib/PEAR -prune \) -not \( -path ./lib/phpseclib -prune \) -not \( -path ./lib/Zend -prune \) -type f -name "*.php" -exec php -d error_reporting=32767 -l {} \; 2>&1 >&- | grep "^"'
- '! find app/design -type f -name "*.phtml" -exec php -d error_reporting=32767 -l {} \; 2>&1 >&- | grep "^"'
- test $TEST_SUITE = "functional" && TEST_FILTER='dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests.php' || true
- if [ $TEST_SUITE == "static" ]; then ! find . -not \( -path ./.phpstorm.meta.php -prune \) -not \( -path ./lib/PEAR -prune \) -not \( -path ./lib/phpseclib -prune \) -not \( -path ./lib/Zend -prune \) -type f -name "*.php" -exec php -d error_reporting=32767 -l {} \; 2>&1 >&- | grep "^"; fi
- if [ $TEST_SUITE == "static" ]; then ! find app/design -type f -name "*.phtml" -exec php -d error_reporting=32767 -l {} \; 2>&1 >&- | grep "^"; fi
- if [ $TEST_SUITE == "functional" ]; then dev/tests/functional/vendor/phpunit/phpunit/phpunit -c dev/tests/$TEST_SUITE $TEST_FILTER; fi
49 changes: 49 additions & 0 deletions dev/travis/before_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

# Copyright © Magento, Inc. All rights reserved.
# http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)

set -e
trap '>&2 echo Error: Command \`$BASH_COMMAND\` on line $LINENO failed with exit code $?' ERR

# mock mail
sudo service postfix stop
echo # print a newline
smtp-sink -d "%d.%H.%M.%S" localhost:2500 1000 &
echo 'sendmail_path = "/usr/sbin/sendmail -t -i "' > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/sendmail.ini

# disable xdebug and adjust memory limit
echo > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
echo 'memory_limit = -1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
phpenv rehash;

# If env var is present, configure support for 3rd party builds which include private dependencies
test -n "$GITHUB_TOKEN" && composer config github-oauth.github.com "$GITHUB_TOKEN" || true

if [ $TEST_SUITE = "functional" ]; then
# Install apache
sudo apt-get update
sudo apt-get install apache2 libapache2-mod-fastcgi
if [ ${TRAVIS_PHP_VERSION:0:1} == "7" ]; then
sudo cp ${TRAVIS_BUILD_DIR}/dev/travis/config/www.conf ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/
fi

# Enable php-fpm
sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
sudo a2enmod rewrite actions fastcgi alias
echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm

# Configure apache virtual hosts
sudo cp -f ${TRAVIS_BUILD_DIR}/dev/travis/config/apache_virtual_host /etc/apache2/sites-available/000-default.conf
sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/000-default.conf
sudo sed -e "s?%MAGENTO_HOST_NAME%?${MAGENTO_HOST_NAME}?g" --in-place /etc/apache2/sites-available/000-default.conf

sudo usermod -a -G www-data travis
sudo usermod -a -G travis www-data

phpenv config-rm xdebug.ini
sudo service apache2 restart

/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -screen 0 1280x1024x24
fi
54 changes: 54 additions & 0 deletions dev/travis/before_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

# Copyright © Magento, Inc. All rights reserved.
# http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)

set -e
trap '>&2 echo Error: Command \`$BASH_COMMAND\` on line $LINENO failed with exit code $?' ERR

# prepare for test suite
case $TEST_SUITE in
static)
cd dev/tests/static

echo "==> preparing changed files list"
changed_files_ce="$TRAVIS_BUILD_DIR/dev/tests/static/testsuite/Magento/Test/_files/changed_files_ce.txt"
php get_github_changes.php \
--output-file="$changed_files_ce" \
--base-path="$TRAVIS_BUILD_DIR" \
--repo='https://github.com/OpenMage/magento-lts.git' \
--branch="$TRAVIS_BRANCH"
sed 's/^/ + including /' "$changed_files_ce"

cd ../../..
;;
functional)
echo "Installing Magento"
mysql -uroot -e 'CREATE DATABASE magento;'
php -f install.php -- \
--license_agreement_accepted yes \
--locale en_US --timezone "America/Los_Angeles" --default_currency USD \
--db_host 127.0.0.1 --db_name magento --db_user root --db_pass "" \
--url "http://${MAGENTO_HOST_NAME}/" --use_rewrites yes --use_secure no \
--admin_lastname Owner --admin_firstname Store --admin_email "[email protected]" \
--admin_username admin --admin_password 123123 \
--encryption_key "I2V7t7fiCIRKw9FWz4m3CStgeBG1T+ATZ0Us+W8jAIk="

echo "Prepare functional tests for running"
cd dev/tests/functional

composer install && composer require se/selenium-server-standalone:2.53.1
export DISPLAY=:1.0
sh ./vendor/se/selenium-server-standalone/bin/selenium-server-standalone -port 4444 -host 127.0.0.1 \
-Dwebdriver.firefox.bin=$(which firefox) -trustAllSSLCertificate &> ~/selenium.log &

cp ./phpunit.xml.dist ./phpunit.xml
sed -e "s?127.0.0.1?${MAGENTO_HOST_NAME}?g" --in-place ./phpunit.xml
sed -e "s?basic?travis_acceptance?g" --in-place ./phpunit.xml
cp ./.htaccess.sample ./.htaccess
cd ./utils
php -f mtf troubleshooting:check-all

cd ../../..
;;
esac
20 changes: 20 additions & 0 deletions dev/travis/config/apache_virtual_host
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<VirtualHost *:80>
DocumentRoot %TRAVIS_BUILD_DIR%
ServerName %MAGENTO_HOST_NAME%

<Directory "%TRAVIS_BUILD_DIR%">
Options FollowSymLinks MultiViews ExecCGI
AllowOverride All
Require all granted
</Directory>

<IfModule mod_fastcgi.c>
AddHandler php7-fcgi .php
Action php7-fcgi /php7-fcgi
Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -host 127.0.0.1:9000 -pass-header Authorization
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>
</VirtualHost>
14 changes: 14 additions & 0 deletions dev/travis/config/www.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[www]

user = www-data
group = www-data

listen = 127.0.0.1:9000

pm = dynamic
pm.max_children = 10
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6

chdir = /

0 comments on commit c57d92c

Please sign in to comment.