diff --git a/.docker/Dockerfile b/.docker/Dockerfile new file mode 100644 index 0000000..b8242fa --- /dev/null +++ b/.docker/Dockerfile @@ -0,0 +1,34 @@ +FROM php:7.1-fpm + +RUN apt-get update + +RUN apt-get install -y zlib1g-dev libpq-dev git libicu-dev libxml2-dev libpng-dev libjpeg-dev libmcrypt-dev libxslt-dev libfreetype6-dev \ + && docker-php-ext-configure intl \ + && docker-php-ext-install intl \ + && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \ + && docker-php-ext-install mysqli pdo pdo_mysql \ + && docker-php-ext-install zip \ + && docker-php-ext-install xml \ + && docker-php-ext-configure gd --with-png-dir=/usr/local/ --with-jpeg-dir=/usr/local/ --with-freetype-dir=/usr/local/ \ + && docker-php-ext-install gd \ + && docker-php-ext-install mcrypt \ + && docker-php-ext-install bcmath \ + && docker-php-ext-install soap \ + && docker-php-ext-install xsl \ + && docker-php-ext-install mbstring + +RUN apt-get install -y subversion +RUN apt-get install -y wget + +RUN wget -O /usr/bin/phpunit https://phar.phpunit.de/phpunit-6.phar && chmod +x /usr/bin/phpunit +RUN curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer + +RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - +RUN apt-get install -y nodejs + +# Set timezone +RUN rm /etc/localtime +RUN ln -s /usr/share/zoneinfo/Europe/Moscow /etc/localtime +RUN "date" + +WORKDIR /code \ No newline at end of file diff --git a/.env-dist b/.env-dist new file mode 100644 index 0000000..17a33c9 --- /dev/null +++ b/.env-dist @@ -0,0 +1,6 @@ +DB_NAME=wc_retailcrm_test +DB_USER=wc_retailcrm +DB_PASS=wc_retailcrm +DB_HOST=mysql +WP_VERSION=4.4 +WC_VERSION=3.0.0 diff --git a/.gitignore b/.gitignore index 5b40963..6cf54b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /nbproject/ /vendor/ .idea/ +.env diff --git a/.travis.yml b/.travis.yml index 46d3ced..9eb229c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,10 +13,41 @@ before_script: - nvm install 10 - make install -script: make tests +env: + global: + - DB_NAME=wc_retailcrm_test + - DB_USER=root + - DB_PASS='' + - DB_HOST=localhost + +script: make test jobs: include: + - php: 5.6 + env: WP_VERSION=latest WC_VERSION=3.8.0 WP_MULTISITE=0 + - php: 7.0 + env: WP_VERSION=latest WC_VERSION=3.8.0 WP_MULTISITE=0 + - php: 7.1 + env: WP_VERSION=latest WC_VERSION=3.8.0 WP_MULTISITE=0 + - php: 7.2 + env: WP_VERSION=latest WC_VERSION=3.8.0 WP_MULTISITE=0 USE_COMPOSER=1 + - php: 5.6 + env: WP_VERSION=latest WC_VERSION=3.9.0 WP_MULTISITE=0 + - php: 7.0 + env: WP_VERSION=latest WC_VERSION=3.9.0 WP_MULTISITE=0 + - php: 7.1 + env: WP_VERSION=latest WC_VERSION=3.9.0 WP_MULTISITE=0 + - php: 7.2 + env: WP_VERSION=latest WC_VERSION=3.9.0 WP_MULTISITE=0 USE_COMPOSER=1 + - php: 5.6 + env: WP_VERSION=4.4 WC_VERSION=3.2.0 WP_MULTISITE=0 + - php: 7.0 + env: WP_VERSION=4.4 WC_VERSION=3.2.0 WP_MULTISITE=0 + - php: 7.1 + env: WP_VERSION=4.4 WC_VERSION=3.2.0 WP_MULTISITE=0 + - php: 7.2 + env: WP_VERSION=4.4 WC_VERSION=3.2.0 WP_MULTISITE=0 USE_COMPOSER=1 - php: 5.6 env: WP_VERSION=4.4 WC_VERSION=3.0.0 WP_MULTISITE=0 - php: 7.0 diff --git a/Makefile b/Makefile index 193a0fd..b231783 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ FILE = $(TRAVIS_BUILD_DIR)/VERSION VERSION = `cat $(FILE)` -.PHONY: tests +.PHONY: test all: svn_clone svn_push remove_dir @@ -28,14 +28,17 @@ compile_pot: msgfmt resources/pot/retailcrm-es_ES.pot -o src/languages/retailcrm-es_ES.mo install: - bash tests/bin/install.sh wc_retailcrm_test root '' localhost $(WP_VERSION) $(WC_VERSION) + bash tests/bin/install.sh $(DB_NAME) $(DB_USER) $(DB_PASS) $(DB_HOST) $(WP_VERSION) $(WC_VERSION) $(SKIP_DB_CREATE) ifeq ($(USE_COMPOSER),1) composer install endif -tests: +test: ifeq ($(USE_COMPOSER),1) vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist else phpunit -c phpunit.xml.dist -endif \ No newline at end of file +endif + +local_test: install + phpunit -c phpunit.xml.dist diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..75b9f70 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,34 @@ +version: '3' +services: + app: + build: + context: ./.docker + volumes: + - ./:/code + links: + - "mysql" + #user: ${UID:-1000}:${GID:-1000} + depends_on: + - mysql + entrypoint: make local_test + env_file: + - ./.env + environment: + - DB_NAME=${DB_NAME} + - DB_USER=${DB_USER} + - DB_PASS=${DB_PASS} + - DB_HOST=${DB_HOST} + - WP_VERSION=${WP_VERSION} + - WC_VERSION=${WC_VERSION} + - SKIP_DB_CREATE=true + mysql: + image: mysql:5.7 + env_file: + - ./.env + environment: + - MYSQL_DATABASE=${DB_NAME} + - MYSQL_USER=${DB_USER} + - MYSQL_PASSWORD=${DB_PASS} + - MYSQL_ROOT_PASSWORD=root + ports: + - "3306:3306" diff --git a/tests/bin/install.sh b/tests/bin/install.sh index 9763093..264afce 100755 --- a/tests/bin/install.sh +++ b/tests/bin/install.sh @@ -11,8 +11,8 @@ DB_USER=$2 DB_PASS=$3 DB_HOST=${4-localhost} WP_VERSION=${5-latest} -SKIP_DB_CREATE=${6-false} -WC_VERSION=${7-3.9.0} +WC_VERSION=${6-3.9.0} +SKIP_DB_CREATE=${7-false} WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib} WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/} @@ -70,6 +70,8 @@ install_wp() { } install_woocommerce() { + if [[ ! -d "/tmp/woocommerce" ]] + then cd /tmp git clone https://github.com/woocommerce/woocommerce.git cd woocommerce @@ -77,6 +79,7 @@ install_woocommerce() { composer install npm install cd - + fi } install_test_suite() { @@ -130,8 +133,10 @@ install_db() { fi fi - # create database - mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA + if [ ${DB_HOST} == "localhost" ]; then + # create database + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA --host=$DB_HOST + fi } install_wp