cancel
Showing results for 
Search instead for 
Did you mean: 

How to test module in different Magento and PHP versions using CI?

SOLVED
Highlighted

How to test module in different Magento and PHP versions using CI?

I have an open-source module in Github and I'd like to automatically test it via CI using the Magento Coding Standard and different Magento installations in different PHP versions. For example:

 

Magento Enterprise 2.3 + PHP 7.2

Magento Community 2.4 + PHP 7.3

 

How could I implement it?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: How to test module in different Magento and PHP versions using CI?

First of all, you have to implement the Magento Coding Standard, then you can create a Travis config file to set the PHP version that you want to test your module and the Magento version and edition, for example:

PHP 7.2

- Magento OpenSource (2.3.2, 2.3.3-p1)
- Magento Commerce (2.3.2, 2.3.3-p1)

PHP 7.3

- Magento OpenSource (2.3.3-p1, 2.3.4-p2)
- Magento Commerce (2.3.3-p1, 2.3.4-p2)

Magento 2 CI Github

Magento Coding Standard

To install the Magento's coding standards in your module first add the Composer package:

php bin/magento setup:di:compile

Then add these lines in your composer.json, I'm considering that you module is inside an src folder.

...
    "scripts": {
        "post-install-cmd": [
            "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
        ],
        "post-update-cmd": [
            "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
        ],
        "php": "vendor/bin/phpcs --standard=./vendor/phpcompatibility/php-compatibility/PHPCompatibility --extensions=php,phtml -d memory_limit=-1 src",
        "lint": "vendor/bin/phpcs --standard=Magento2 src",
        "fix": "vendor/bin/phpcbf --standard=Magento2 src"
    }
...
Automated tests

In order to set up the automated tests I recommend using Travis CI with Github, to do so, you just need to create these files below. And add your Magento user and password in the Travis panel as MAGENTO_USERNAME and MAGENTO_PASSWORD.

 

.travis.yml
bin/before_install.sh
bin/prepare_php.sh
bin/test_magento.sh
 

View solution in original post

1 REPLY 1
Highlighted

Re: How to test module in different Magento and PHP versions using CI?

First of all, you have to implement the Magento Coding Standard, then you can create a Travis config file to set the PHP version that you want to test your module and the Magento version and edition, for example:

PHP 7.2

- Magento OpenSource (2.3.2, 2.3.3-p1)
- Magento Commerce (2.3.2, 2.3.3-p1)

PHP 7.3

- Magento OpenSource (2.3.3-p1, 2.3.4-p2)
- Magento Commerce (2.3.3-p1, 2.3.4-p2)

Magento 2 CI Github

Magento Coding Standard

To install the Magento's coding standards in your module first add the Composer package:

php bin/magento setup:di:compile

Then add these lines in your composer.json, I'm considering that you module is inside an src folder.

...
    "scripts": {
        "post-install-cmd": [
            "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
        ],
        "post-update-cmd": [
            "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
        ],
        "php": "vendor/bin/phpcs --standard=./vendor/phpcompatibility/php-compatibility/PHPCompatibility --extensions=php,phtml -d memory_limit=-1 src",
        "lint": "vendor/bin/phpcs --standard=Magento2 src",
        "fix": "vendor/bin/phpcbf --standard=Magento2 src"
    }
...
Automated tests

In order to set up the automated tests I recommend using Travis CI with Github, to do so, you just need to create these files below. And add your Magento user and password in the Travis panel as MAGENTO_USERNAME and MAGENTO_PASSWORD.

 

.travis.yml
bin/before_install.sh
bin/prepare_php.sh
bin/test_magento.sh
 

View solution in original post