7

How can I prepare a CI script to check the syntax and code quality of my extension code?

It's not necessary to run Unit Test or Integration Test, I'm using Bitbucket and I would like to use Bitbucket Pipelines.

8

Add the AUTH variable into the Pipelines Variable settings.

Magento 2 Bitbucket Pipelines

Using Bitbucket, you can use this file below called bitbucket-pipelines.yml

    image: rafaelcgstz/magento2
    pipelines:
      branches:
        master:
          - step:
              name: Composer install
              caches:
                - composer
              artifacts:
                - vendor/**
              script:
                - echo "$AUTH" > auth.json
                - composer install --prefer-dist --optimize-autoloader
          - parallel:
            - step:
                name: PHP CodeSniffer
                caches:
                  - composer
                artifacts:
                  - vendor/**
                script:
                  - php vendor/bin/phpcs --standard=PSR2 Api/ Helper/ Model/ Plugin/ Setup/
            - step:
                name: PHP Mess Detector
                caches:
                  - composer
                artifacts:
                  - vendor/**
                script:
                  - php vendor/bin/phpmd Api/,Helper/,Model/,Plugin/,Setup/ text cleancode,codesize,controversial,design,naming,unusedcode
            - step:
                name: PHP Copy/Paste Detector
                caches:
                  - composer
                artifacts:
                  - vendor/**
                script:
                  - php vendor/bin/phpcpd Api/ Helper/ Model/ Plugin/ Setup/    

Your composer.json needs to be like this below:

{
    "name": "mycompany/modulename",
    "description": "",
    "type": "magento2-module",
    "version": "1.0.0",
    "license": [
        "proprietary"
    ],
    "authors":[
        {
            "name":"Rafael Correa Gomes",
            "email":"rgomes@magento.com"
        }
    ],
    "repositories": [
        {
            "type": "composer",
            "url": "https://repo.magento.com/"
        }
    ],
    "require": {
        "php": "~5.6.0|~7.0.0",
        "magento/module-backend": "100.0.*",
        "magento/module-catalog": "100.0.*",
        "magento/module-eav": "100.0.*",
        "magento/module-layered-navigation": "100.0.*",
        "magento/framework": "100.0.*"
    },
    "require-dev": {
        "phpunit/phpunit": "^4.8",
        "phpmd/phpmd": "^2.3",
        "squizlabs/php_codesniffer": "^2.5",
        "sebastian/phpcpd": "^2.0",
        "satooshi/php-coveralls": "^1.0"
    },
    "autoload": {
        "files": [
            "registration.php"
        ],
        "psr-4": {
            "MyCompany\\ModuleName\\": ""
        }
    }
}

Reference: Get started with Bitbucket Pipelines

  • Exactly what I was lookinf for. Thanks! Maybe you can add an example how to setup unit/integration test? – sv3n Sep 25 '18 at 19:30
  • If its your dockjer image, can you please add phpstan (v0.8.5)? – sv3n Oct 25 '18 at 17:46
  • @sv3n did you figure out how to run the unit/integration test? – Haim Feb 20 at 4:31
  • @rafael 1. Why do you need the first step? it doesn't seem to be doing anything, unless I'm missing something obvious? 2. You are only passing in your magento username and password on the first step, our pipeline fails unless we pass in the credentials in every step – Haim Feb 20 at 15:28
  • @Haim No need to pass the credentials on every step since required credentials are echoed to the auth.json. – Adnan Feb 25 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.