Skip to content

MageTestStand fork with Gitlab-CI integration and composer.json dependency install

License

Notifications You must be signed in to change notification settings

gpaddis/MageTestStand

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MageTestStand

This tool is used to build a minimal Magento environment that allows to run PHPUnit tests for a Magento module on Travis CI.

It uses following tools:

Requirements

  • Main Database: defaults to 'mageteststand' (user 'root', blank password) This is the database Magento uses
  • Test Database: main database name with '_test' appended: 'mageteststand_test' (host, username, password and port are the same as the main database) This is the dummy database EcomDev_PHPUnit will use. Although you can configure this to use the original database, some tests (including fixtures) will behave differently...
  • You can override the default database credentials using following environment variables:
    • MAGENTO_DB_HOST
    • MAGENTO_DB_PORT
    • MAGENTO_DB_USER
    • MAGENTO_DB_PASS
    • MAGENTO_DB_NAME
  • In case you want to allow EcomDev_PHPUnit to use the main database instead of the test database you can set following environment variable to 1. This might be required if you're planning on writing integration tests.
    • MAGENTO_DB_ALLOWSAME
  • Environment variable MAGENTO_VERSION with valid Magento version for n98-magerun's install command
  • If you have specified additional dependencies in your composer.json file and you need to install them to run the test, set the following environment variable to 1.
    • INSTALL_DEPENDENCIES

General usage

  • Set the environment variable MAGENTO_VERSION to the desired version, e.g. magento-ce-1.9.0.1
  • Set the environment variable WORKSPACE to the directory of the magento module
  • checkout your magento module
  • run curl -sSL https://raw.githubusercontent.com/AOEpeople/MageTestStand/master/setup.sh | bash as the build step, this will do everything automatically in a temporary directory
  • you can use the script contents as a build step for sure, but this way it's easier ;)

Travis CI configuration

Example .travis.yaml file (in the Magento module you want to test):

language: php
php:
  - 5.3
  - 5.4
  - 5.5
  - 5.6
  - hhvm
matrix:
  allow_failures:
  - php: 5.6
  - php: hhvm
env:
#  global:
#    - MAGENTO_DB_ALLOWSAME=1
#    - SKIP_CLEANUP=1
  - MAGENTO_VERSION=magento-ce-1.9.0.1
  - MAGENTO_VERSION=magento-ce-1.8.1.0
  - MAGENTO_VERSION=magento-ce-1.8.0.0
  - MAGENTO_VERSION=magento-ce-1.7.0.2
script:
  - curl -sSL https://raw.githubusercontent.com/AOEpeople/MageTestStand/master/setup.sh | bash
notifications:
  email:
    recipients:
      - notify@someone.com
    on_success: always
    on_failure: always

Jenkins configuration

  • create a new multiconfiguration project and check out your Magento Module.
  • create a new axis on the configuration matrix, named "MAGENTO_VERSION" and add the following values
magento-ce-1.9.0.1
magento-ce-1.8.1.0
magento-ce-1.8.0.0
magento-ce-1.7.0.2
  • Make sure that the configurations are build sequentiell, otherwise you might run into database issues!
  • use the following script as a shell build step curl -sSL https://raw.githubusercontent.com/AOEpeople/MageTestStand/master/setup.sh | bash

GitLab CI configuration

First, create the file ci/docker_install.sh in your module to install the dependencies for the docker runner.

#!/bin/bash

# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && exit 0

set -xe

# Install git (the php image doesn't have it) which is required by composer
apt-get update -yqq
apt-get install git libpng-dev libmcrypt-dev libxml2-dev -yqq

# Here you can install any extension that you need
docker-php-ext-configure mcrypt
docker-php-ext-install pdo_mysql gd mcrypt zip soap

Example .gitlab-ci.yml file (in the Magento module you want to test):

before_script:
  - bash ci/docker_install.sh > /dev/null

.test_variables: &test_variables
    MAGENTO_VERSION: magento-mirror-1.9.3.4
    INSTALL_DEPENDENCIES: 1
    # Configure mysql environment variables (https://hub.docker.com/r/_/mysql/)
    MYSQL_DATABASE: magento
    MYSQL_ROOT_PASSWORD: root
    # Credentials for MageTestStand
    MAGENTO_DB_HOST: mysql
    MAGENTO_DB_USER: root
    MAGENTO_DB_NAME: $MYSQL_DATABASE
    MAGENTO_DB_PASS: $MYSQL_ROOT_PASSWORD
    MAGENTO_DB_ALLOWSAME: 1

.run_tests: &run_tests
  stage: test
  services:
    - mysql:5.7
  variables:
    <<: *test_variables
  script:
  - curl -sSL https://raw.githubusercontent.com/gpaddis/MageTestStand/master/setup.sh | bash

# Define a job for each PHP version you want to run the test on
test:php5.6:
  image: php:5.6
  <<: *run_tests

Unittest your Module directly from bash/zsh/shell

  • Set up your environment
export WORKSPACE=/full/path/to/your/module
export MAGENTO_VERSION=magento-ce-1.9.0.1

# if necessary
export MAGENTO_DB_HOST=somewhere
export MAGENTO_DB_PORT=somenum
export MAGENTO_DB_USER=someone
export MAGENTO_DB_PASS=something
export MAGENTO_DB_NAME=somename
  • Run MageTestStand:
curl -sSL https://raw.githubusercontent.com/AOEpeople/MageTestStand/master/setup.sh | bash

Misc

Skip cleanup

If you're running this in an CI environment that will delete the workspace after the run (e.g. Travis CI) you might not want to wait for this script to explicitely cleanup. Using SKIP_CLEANUP parameter you can make MageTestStand skip this step.

This parameter can be set via an environment variable (Travis CI supports that via env/global) or from command line:

export SKIP_CLEANUP=1

About

MageTestStand fork with Gitlab-CI integration and composer.json dependency install

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 88.3%
  • PHP 11.7%