Skip to content

Commit

Permalink
run tests with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Nakiami committed May 4, 2018
1 parent 235489f commit 8803fd8
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 122 deletions.
18 changes: 1 addition & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,8 @@ notifications:

sudo: required

language: php

php:
- 7.0

services:
- mysql

addons:
hosts:
- mellivora

before_script:
# Environment setup
- bash tests/ci/setup_environment

# Mellivora setup and configuration
- bash tests/ci/setup_mellivora
- docker

script:
- bash tests/run_tests --debug
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN docker-php-ext-install mbstring curl pdo pdo_mysql
COPY . /var/www/mellivora
COPY install/lamp/mellivora.apache.conf /etc/apache2/sites-available/000-default.conf

ENV COMPOSER_ALLOW_SUPERUSER=1
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
RUN composer global require hirak/prestissimo
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: '3'
services:
app:
mellivora:
image: mellivora
ports:
- 80:80
Expand Down
46 changes: 46 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: '3'
services:
codecept:
image: eccube/php7-ext-codeception
depends_on:
- chrome
- mellivora-test
- db-test
volumes:
- .:/project
chrome:
image: 'selenium/standalone-chrome-debug'
ports:
- '5900'
- '4444'
dns: 8.8.4.4
environment:
- no_proxy=localhost
mellivora-test:
image: mellivora-test
build:
context: .
dockerfile: Dockerfile
environment:
MELLIVORA_CONFIG_DB_ENGINE: mysql
MELLIVORA_CONFIG_DB_HOST: db-test
MELLIVORA_CONFIG_DB_PORT: 3306
MELLIVORA_CONFIG_DB_NAME: mellivora
MELLIVORA_CONFIG_DB_USER: meldbuser
MELLIVORA_CONFIG_DB_PASSWORD: password
MELLIVORA_CONFIG_SITE_URL: http://mellivora-test/
MELLIVORA_CONFIG_SITE_URL_STATIC_RESOURCES: http://mellivora-test/
volumes:
- .:/var/www/mellivora
- composerdependencies:/var/www/mellivora/include/thirdparty/composer
links:
- db-test
db-test:
image: mysql:5.6
environment:
MYSQL_DATABASE: mellivora
MYSQL_USER: meldbuser
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
volumes:
composerdependencies:
6 changes: 4 additions & 2 deletions htdocs/css/mellivora.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ body {
background-color: rgba(234, 234, 234, 0.75);
}

#menu-main a, form {
#menu-main a {
padding: 7px 15px;
margin: 5px 5px;
border-radius: 4px;
Expand All @@ -94,10 +94,12 @@ body {
#menu-main button {
background: none;
border: none;
padding: 0;
width: 80px;
height: 40px;
font: inherit;
cursor: pointer;
color: #428BCA;
margin: 2px 0 0 0;
}

#categories-menu a {
Expand Down
2 changes: 1 addition & 1 deletion tests/build_sql_dump
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cat << EOF
EOF

cat >${DUMP_FILE} << EOL
/* This file was generated by ${0} */
/* This file was automatically generated by the test runner */
EOL

Expand Down
38 changes: 0 additions & 38 deletions tests/ci/setup_environment

This file was deleted.

27 changes: 0 additions & 27 deletions tests/ci/setup_mellivora

This file was deleted.

2 changes: 1 addition & 1 deletion tests/codeception/_data/sql/dump.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/* This file will be automatically generated by the build_sql_dump script */
/* This file was automatically generated by the test runner */
6 changes: 3 additions & 3 deletions tests/codeception/_data/sql/setup/create_database.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DROP DATABASE IF EXISTS mellivora_ci;
CREATE DATABASE IF NOT EXISTS mellivora_ci CHARACTER SET utf8 COLLATE utf8_general_ci;
USE mellivora_ci;
DROP DATABASE IF EXISTS mellivora;
CREATE DATABASE IF NOT EXISTS mellivora CHARACTER SET utf8 COLLATE utf8_general_ci;
USE mellivora;

2 changes: 1 addition & 1 deletion tests/codeception/_support/AcceptanceTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private function logIn($email, $password) {

$I->click('#login-button');

$I->waitForText('Log out', 5); # I am logged in
$I->waitForElementVisible('#logout-button', 5); # I am logged in
$I->seeInCurrentUrl('/scores'); # I have been redirected back to where I started
}

Expand Down
7 changes: 4 additions & 3 deletions tests/codeception/acceptance.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://mellivora/
url: http://mellivora-test/
browser: chrome
host: chrome
- Db:
dsn: 'mysql:host=localhost;dbname=mellivora_ci'
dsn: 'mysql:host=db-test;port=3306;dbname=mellivora'
user: 'root'
password: ''
password: 'password'
dump: 'tests/codeception/_data/sql/dump.sql'
populate: true
cleanup: false
Expand Down
34 changes: 6 additions & 28 deletions tests/run_tests
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
#!/bin/bash -x

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

CODECEPT=$(which codecept)
if [ -z ${CODECEPT} ] || [ ! -x ${CODECEPT} ];
then
if [ ! -x "codecept" ];
then
echo "Could not find suitable global or local codecept. Downloading.."
wget --no-verbose --output-document codecept http://codeception.com/codecept.phar
chmod +x codecept
fi

CODECEPT="./codecept"
fi
COMPOSE="docker-compose -f docker-compose.test.yml"

# since Codeception is limited to one db dump to import,
# we need to collect all our SQL dump data into one file
bash "${DIR}/build_sql_dump"

${CODECEPT} clean
${CODECEPT} build
${CODECEPT} run "$@"
${COMPOSE} up -d
echo "Waiting for MySQL docker image to finish starting.." && sleep 5;
${COMPOSE} run --rm codecept clean
${COMPOSE} run --rm codecept run "$@"
${COMPOSE} down

# output extra information if tests are running on Travis CI
if [ "${?}" != "0" ] && [ "${TRAVIS_BUILD_DIR}" != "" ];
Expand All @@ -32,18 +22,6 @@ then
EOF

echo "--- Apache General error log ---"
sudo cat "/var/log/apache2/error.log"
echo "--- End Apache General error log ---"

echo "--- Apache Mellivora error log ---"
sudo cat "/var/log/apache2/mellivora-error.log"
echo "--- End Apache Mellivora error log ---"

echo "--- MySQL error log ---"
sudo cat "/var/log/mysql/error.log"
echo "--- End MySQL error log ---"

echo "--- Stored error pages ---"
for file_name in ${DIR}/codeception/_output/*.html; do
echo "--- ${file_name} ---"
Expand Down

0 comments on commit 8803fd8

Please sign in to comment.