📜 ⬆️ ⬇️

Magento Modules and Travis CI

A brief note with examples of configs, how to use Travis CI when developing modules for Magento of both versions.

general information


Sample Application Code:

The application description for Magento 2. The application for Magento 1 is very similar in structure and deployment method.

Each of the modules in question is the head module of a Magento application (contains instructions for deploying the target web application and connecting other modules to it). Deployment can occur in one of three options:

In each of the options, first with the help of PHP Composer, the Magento itself is deployed to a separate directory, and then the module files are mounted into the deployed application (copied during the live deployment, linked via symbolic links in other cases). After that, the Magento-installer is launched, which creates, if necessary, the initial database, and an SQL script that changes default values ​​in the initial database depending on the type of deployment (switching on symbolic links, logging, etc.).

In order not to produce entities, for development (work) and CI testing (travis) one set of deployment scripts is used:

The application itself is deployed in the ./work/htdocs/ subdirectory. When deploying in post_install.sh and post_install.sql templates, variables (placeholders — paths, database access parameters, URLs, etc.) are replaced with their effective values ​​from the configuration file ./work/templates.json and the resulting scripts are placed in directory ./work/bin/deploy/ .
')
Testing of all modules included in the application is described in PHPUnit descriptors:

CI for Magento 1


Descriptor for Travis:
sudo: false # use container-based environment on Travis language: php php: - 5.6 - hhvm - '7' before_install: - cd work # go to root folder for development environment - pwd # control current path ('LOCAL_ROOT' in templates.json) - cp templates.json.travis templates.json # create configuration for Travis from template - composer self-update # update composer to prevent error Class 'Composer\Installer\PackageEvents' not found in # .../work/vendor/aydin-hassan/magento-core-composer-installer/src/CoreManager.php on line 109 - composer install # install project using PHP Composer - cat ./bin/deploy/post_install.sh # control parameters in the installation script - cat ./bin/deploy/post_install.sql # control parameters in the SQL script - sh ./bin/deploy/post_install.sh # create initial DB, run SQL script, setup permissions, ... script: - phpunit --configuration ./test/unit/phpunit.dist.xml # run project's unit tests - phpunit --configuration ./test/functional/phpunit.dist.xml # run project's functional tests 


When deploying and testing any special surprises do not occur, the whole process takes about 3-4 minutes.

CI for Magento 2


Descriptor for Travis:
 sudo: required # use Travis standard env (http://docs.travis-ci.com/user/ci-environment/) language: php php: - 5.6 # - hhvm # there is an error on DB installation: "Command option 'language': Invalid value. To see possible values, # ... run command 'bin/magento info:language:list'." before_install: # Setup MySQL 5.6 on Ubuntu 12.04 (thanks to drogus - https://gist.github.com/drogus/6718448): - mysql --version # control version before upgrade - sudo apt-get remove mysql-common mysql-server-5.5 mysql-server-core-5.5 mysql-client-5.5 mysql-client-core-5.5 - sudo apt-get autoremove - sudo apt-get install libaio1 - wget -O mysql-5.6.14.deb http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.14-debian6.0-x86_64.deb/from/http://cdn.mysql.com/ - sudo dpkg -i mysql-5.6.14.deb - sudo cp /opt/mysql/server-5.6/support-files/mysql.server /etc/init.d/mysql.server - sudo ln -s /opt/mysql/server-5.6/bin/* /usr/bin/ # some config values were changed since 5.5 - sudo sed -i'' 's/table_cache/table_open_cache/' /etc/mysql/my.cnf - sudo sed -i'' 's/log_slow_queries/slow_query_log/' /etc/mysql/my.cnf - "sudo sed -i'' 's/basedir[^=]\\+=.*$/basedir = \\/opt\\/mysql\\/server-5.6/' /etc/mysql/my.cnf" # there is an error # ... w/o double quotes: The command "sudo sed -i'' 's/basedir[^=]\+=.*$/basedir = \/opt\/mysql\/server-5.6/' /etc/mysql/my.cnf" failed and exited with 1 during . - sudo /etc/init.d/mysql.server start - mysql --version # control version after upgrade # Deploy Magento 2 application # Go to working folder, copy templates.json for travis and start composer install process - cd work # go to root folder for development environment - pwd # control current path ('LOCAL_ROOT' in templates.json) - cp templates.json.travis templates.json # create configuration for Travis from template # - composer self-update # update composer to prevent error Class 'Composer\Installer\PackageEvents' not found in # .../work/vendor/aydin-hassan/magento-core-composer-installer/src/CoreManager.php on line 109 - composer install # Run post installation script (deploy Magento2 itself) - cat ./bin/deploy/post_install.sh # control parameters in the installation script - sh ./bin/deploy/post_install.sh # create initial DB, setup permissions, ... script: - phpunit --configuration ./test/unit/phpunit.dist.xml # run project's unit tests - phpunit --configuration ./test/functional/phpunit.dist.xml # run project's functional tests # - phpunit --configuration ./htdocs/dev/tests/unit/phpunit.xml.dist # run Magento 2 unit tests 


With Magento 2 everything is somewhat more interesting. First you need to solve the problem with the version of MySQL. The standard environment of Travis (Ubuntu 12.04) uses the MySQL 5.5 server, and Magento 2 requires version 5.6 for itself. Helped a way from a colleague drogus'a.

Then it turned out that apart from the PHP 5.6 version, the deployment nowhere passes. On PHP 7 Magento 2 swears, and on HHVM the installer is not started. Error launching Magento 2 installation, despite the fact that the language parameter is allowed ("en_US"):

 Command option 'language': Invalid value. To see possible values, run command 'bin/magento info:language:list 


PHP 5.6 alone is enough for our needs, so I didn’t even fight with HHVM.

You can also run tests of Magento 2 itself, but on Travis they fall down on 4071st (out of 15062) due to lack of memory:
 .PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 122133 bytes) in /home/travis/build/flancer32/sample_mage2_module/work/vendor/phpunit/phpunit/src/Util/GlobalState.php on line 110 


The whole process of deployment and testing takes about 8-10 minutes.

Source: https://habr.com/ru/post/247349/


All Articles