Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved test environment #11668

Merged
merged 2 commits into from
Apr 14, 2016
Merged

Improved test environment #11668

merged 2 commits into from
Apr 14, 2016

Conversation

sergeyklay
Copy link
Contributor

See: Codeception/Codeception#2779
And: http://codeception.com/03-05-2016/codeception-2.2.-upcoming-features.html#params

How to test Phalcon by using Docker containers? Example:

#!/usr/bin/env bash

docker_bin="$(which docker.io 2> /dev/null || which docker 2> /dev/null)"

#  1) Create Phalcon Network
#  docker network create --driver bridge phalcon_nw

[ -z "$PHP_VERSION" ] && echo "Need to set PHP_VERSION variable. Fox example: 'export PHP_VERSION=7'" && exit 1;
[ -z "$TRAVIS_BUILD_DIR" ] && TRAVIS_BUILD_DIR=$(cd $(dirname "$1") && pwd -P)/$(basename "$1")

#  2) Run required containers inside Phalcon Network (--net=phalcon_nw)
#  and get the corresponding names of their hosts
[ -z "$TEST_DB_MYSQL_HOST" ] && TEST_DB_MYSQL_HOST="phalcon_mysql"
[ -z "$TEST_RS_HOST" ] && TEST_RS_HOST="phalcon_redis"
[ -z "$TEST_MC_HOST" ] && TEST_MC_HOST="phalcon_memcached"
[ -z "$TEST_BT_HOST" ] && TEST_BT_HOST="phalcon_beanstalk"
[ -z "$TEST_DB_MONGO_HOST" ] && TEST_DB_MONGO_HOST="phalcon_mongo"

chmod +x ${TRAVIS_BUILD_DIR}/tests/_ci/entrypoint.sh

#  3) Run tests
${docker_bin} run -it --rm \
    --entrypoint /entrypoint.sh \
    --privileged=true \
    --net=phalcon_nw \
    --name test-phalcon-${PHP_VERSION} \
    -e TEST_DB_MYSQL_DSN="mysql:host=${TEST_DB_MYSQL_HOST};dbname=phalcon_test" \
    -e TEST_DB_MYSQL_HOST="${TEST_DB_MYSQL_HOST}" \
    -e TEST_DB_MYSQL_PORT=3306 \
    -e TEST_DB_MYSQL_USER="root" \
    -e TEST_DB_MYSQL_PASSWD="" \
    -e TEST_DB_MYSQL_NAME="phalcon_test" \
    -e TEST_DB_MYSQL_CHARSET="utf8" \
    -e TEST_RS_HOST="${TEST_RS_HOST}" \
    -e TEST_RS_PORT=6379 \
    -e TEST_MC_HOST="${TEST_MC_HOST}" \
    -e TEST_MC_PORT=11211 \
    -e TEST_BT_HOST="${TEST_BT_HOST}" \
    -e TEST_BT_PORT=11300 \
    -e TEST_DB_MONGO_HOST="${TEST_DB_MONGO_HOST}" \
    -e TEST_DB_MONGO_PORT=27017 \
    -e TEST_DB_MONGO_USER='admin' \
    -e TEST_DB_MONGO_PASSWD='' \
    -e TEST_DB_MONGO_NAME='phalcon_test' \
    -e PHP_VERSION="${PHP_VERSION}" \
    -v ${TRAVIS_BUILD_DIR}/tests/_ci/backtrace.sh:/backtrace.sh \
    -v ${TRAVIS_BUILD_DIR}/tests/_ci/entrypoint.sh:/entrypoint.sh \
    -v ${TRAVIS_BUILD_DIR}/vendor:/app/vendor \
    -v ${TRAVIS_BUILD_DIR}/codeception.yml:/app/codeception.yml \
    -v ${TRAVIS_BUILD_DIR}/tests:/app/tests \
    -v ${TRAVIS_BUILD_DIR}/ext/modules/phalcon.so:/ext/phalcon.so \
    phalconphp/php:${PHP_VERSION} bash

entrypoint.sh:

#!/usr/bin/env bash

PURPLE="\e[0;35m"
GREEN="\033[0;32m"
YELLOW="\e[1;33m"
NC="\033[0m"

echo -e "\nWelcome to the Docker testing container."

mkdir -p /tmp/phalcon
echo "/tmp/phalcon/core-%e.%p" | tee /proc/sys/kernel/core_pattern &> /dev/null

ulimit -c unlimited

export PHP_EXTENSION_DIR=`php-config --extension-dir`

echo -e "If a Segmentation Fault is happens use: ${PURPLE}bash /backtrace.sh${NC}"
echo -e "PHP extension path: ${PURPLE}${PHP_EXTENSION_DIR}${NC}\n"

ln -s /ext/phalcon.so ${PHP_EXTENSION_DIR}/phalcon.so
[[ "$PHP_VERSION" == "7" ]] || ln -s /app/tests/_ci/phalcon.ini /etc/php5/cli/conf.d/50-phalcon.ini;
[[ "$PHP_VERSION" != "7" ]] || ln -s /app/tests/_ci/phalcon.ini /etc/php/7.0/cli/conf.d/50-phalcon.ini;

export PHALCON_VERSION=`php --ri phalcon | grep "Version =" | awk '{print $3}'`

echo -e "${GREEN}Phalcon${NC}     version ${YELLOW}${PHALCON_VERSION}${NC}"
/app/vendor/bin/codecept --version

/app/vendor/bin/codecept build &> /dev/null

echo -e ""
/app/vendor/bin/codecept run -v

result_codecept=$?

if [ ${result_codecept} -ne 0 ]; then
  bash /backtrace.sh
  [[ "$PHP_VERSION" == "7" ]] || exit 1;
  # Allow failures for PHP 7
  [[ "$PHP_VERSION" != "7" ]] || exit 0;
fi

exit 0;

backtrace.sh:

#!/usr/bin/env bash

shopt -s nullglob
export LC_ALL=C

for i in /tmp/phalcon/core-*.*; do
    if [ -f "$i" -a "$(file "$i" | grep -o 'core file')" ]; then
        gdb -q $(which php) "$i" <<EOF
set pagination 0
backtrace full
info registers
x/16i \$pc
thread apply all backtrace
quit
EOF
    fi
done

selection_166

@sergeyklay sergeyklay merged commit 53688ce into phalcon:2.1.x Apr 14, 2016
dump: tests/_data/schemas/mysql/mysql.dump.sql

params:
# get params drom environment vars

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drom? ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drom is the king! All hail Drom!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants